From d6883e6b4b80e4c97bd819dd5abafd2ff4a645bf Mon Sep 17 00:00:00 2001 From: meganrogge Date: Fri, 8 Mar 2024 12:27:22 -0800 Subject: [PATCH] alternate approach --- .../chat/browser/media/terminalChatWidget.css | 4 +++ .../chat/browser/terminalChatActions.ts | 25 ++++++++++++------- .../chat/browser/terminalChatWidget.ts | 21 ++++++++-------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/vs/workbench/contrib/terminalContrib/chat/browser/media/terminalChatWidget.css b/src/vs/workbench/contrib/terminalContrib/chat/browser/media/terminalChatWidget.css index ad8623e881c..3e2b58d2d41 100644 --- a/src/vs/workbench/contrib/terminalContrib/chat/browser/media/terminalChatWidget.css +++ b/src/vs/workbench/contrib/terminalContrib/chat/browser/media/terminalChatWidget.css @@ -22,3 +22,7 @@ .terminal-inline-chat .chatMessageContent { width: 400px !important; } + +.interactive-result-code-block-toolbar { + margin-top: 7px; +} diff --git a/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatActions.ts b/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatActions.ts index 36e07a4f19a..2d30d5519fa 100644 --- a/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatActions.ts +++ b/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatActions.ts @@ -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)) { diff --git a/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.ts b/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.ts index 1743043d9e3..950d54fcd5d 100644 --- a/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.ts +++ b/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.ts @@ -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',