mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-15 10:15:04 +01:00
alternate approach
This commit is contained in:
@@ -22,3 +22,7 @@
|
||||
.terminal-inline-chat .chatMessageContent {
|
||||
width: 400px !important;
|
||||
}
|
||||
|
||||
.interactive-result-code-block-toolbar {
|
||||
margin-top: 7px;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { Codicon } from 'vs/base/common/codicons';
|
||||
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
||||
import { localize2 } from 'vs/nls';
|
||||
import { MenuId } from 'vs/platform/actions/common/actions';
|
||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { TerminalSettingId } from 'vs/platform/terminal/common/terminal';
|
||||
@@ -165,10 +166,13 @@ registerActiveXtermAction({
|
||||
},
|
||||
menu: {
|
||||
// TODO: Allow action to be made primary, the action list is hardcoded within InlineChatWidget
|
||||
id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
|
||||
group: '0_main',
|
||||
order: 0,
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.requestActive.negate()),
|
||||
// id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
|
||||
// group: '0_main',
|
||||
// order: 0,
|
||||
// when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.requestActive.negate()),
|
||||
id: MenuId.ChatCodeBlock,
|
||||
group: 'navigation',
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.requestActive.negate())
|
||||
},
|
||||
run: (_xterm, _accessor, activeInstance) => {
|
||||
if (isDetachedTerminalInstance(activeInstance)) {
|
||||
@@ -190,17 +194,20 @@ registerActiveXtermAction({
|
||||
TerminalChatContextKeys.agentRegistered,
|
||||
TerminalChatContextKeys.responseContainsCodeBlock
|
||||
),
|
||||
icon: Codicon.check,
|
||||
icon: Codicon.pencil,
|
||||
keybinding: {
|
||||
when: TerminalChatContextKeys.requestActive.negate(),
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
primary: KeyMod.Alt | KeyCode.Enter,
|
||||
},
|
||||
menu: {
|
||||
id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
|
||||
group: '0_main',
|
||||
order: 1,
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.requestActive.negate()),
|
||||
// id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
|
||||
// group: '0_main',
|
||||
// order: 1,
|
||||
// when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.requestActive.negate()),
|
||||
id: MenuId.ChatCodeBlock,
|
||||
group: 'navigation',
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.requestActive.negate())
|
||||
},
|
||||
run: (_xterm, _accessor, activeInstance) => {
|
||||
if (isDetachedTerminalInstance(activeInstance)) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import { Dimension, IFocusTracker, trackFocus } from 'vs/base/browser/dom';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import 'vs/css!./media/terminalChatWidget';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
@@ -30,7 +31,8 @@ export class TerminalChatWidget extends Disposable {
|
||||
terminalElement: HTMLElement,
|
||||
private readonly _instance: ITerminalInstance,
|
||||
@IInstantiationService private readonly _instantiationService: IInstantiationService,
|
||||
@IContextKeyService private readonly _contextKeyService: IContextKeyService
|
||||
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
|
||||
@ICodeEditorService private readonly _codeEditorService: ICodeEditorService
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -126,12 +128,16 @@ export class TerminalChatWidget extends Disposable {
|
||||
this._inlineChatWidget.value = value ?? '';
|
||||
}
|
||||
acceptCommand(shouldExecute: boolean): void {
|
||||
// Trim command to remove any whitespace, otherwise this may execute the command
|
||||
const value = parseCodeFromBlock(this._inlineChatWidget?.responseContent?.trim());
|
||||
if (!value) {
|
||||
const editor = this._codeEditorService.getFocusedCodeEditor() || this._codeEditorService.getActiveCodeEditor();
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
this._instance.runCommand(value, shouldExecute);
|
||||
const model = editor.getModel();
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
const code = editor.getValue();
|
||||
this._instance.runCommand(code, shouldExecute);
|
||||
this.hide();
|
||||
}
|
||||
updateProgress(progress?: IChatProgress): void {
|
||||
@@ -142,11 +148,6 @@ export class TerminalChatWidget extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
function parseCodeFromBlock(block?: string): string | undefined {
|
||||
const match = block?.match(/```.*?\n([\s\S]*?)```/);
|
||||
return match ? match[1].trim() : undefined;
|
||||
}
|
||||
|
||||
const enum ChatElementSelectors {
|
||||
ResponseEditor = '.chatMessageContent textarea',
|
||||
ResponseMessage = '.chatMessageContent',
|
||||
|
||||
Reference in New Issue
Block a user