diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.ts b/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.ts index 3c75e0c503c..2266ef267ee 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.ts @@ -5,7 +5,6 @@ import { Codicon } from '../../../../../base/common/codicons.js'; import { KeyCode, KeyMod } from '../../../../../base/common/keyCodes.js'; -import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js'; import { Selection } from '../../../../../editor/common/core/selection.js'; import { localize, localize2 } from '../../../../../nls.js'; import { Action2, MenuId, registerAction2 } from '../../../../../platform/actions/common/actions.js'; @@ -14,7 +13,6 @@ import { KeybindingWeight } from '../../../../../platform/keybinding/common/keyb import { CHAT_CATEGORY } from './chatActions.js'; import { IQuickChatOpenOptions, IQuickChatService } from '../chat.js'; import { ChatContextKeys } from '../../common/chatContextKeys.js'; -import { InlineChatController } from '../../../inlineChat/browser/inlineChatController.js'; export const ASK_QUICK_QUESTION_ACTION_ID = 'workbench.action.quickchat.toggle'; export function registerQuickChatActions() { @@ -65,37 +63,6 @@ export function registerQuickChatActions() { } }); - registerAction2(class LaunchInlineChatFromQuickChatAction extends Action2 { - constructor() { - super({ - id: 'workbench.action.quickchat.launchInlineChat', - title: localize2('chat.launchInlineChat.label', "Launch Inline Chat"), - f1: false, - category: CHAT_CATEGORY - }); - } - - async run(accessor: ServicesAccessor) { - const quickChatService = accessor.get(IQuickChatService); - const codeEditorService = accessor.get(ICodeEditorService); - if (quickChatService.focused) { - quickChatService.close(); - } - const codeEditor = codeEditorService.getActiveCodeEditor(); - if (!codeEditor) { - return; - } - - const controller = InlineChatController.get(codeEditor); - if (!controller) { - return; - } - - await controller.run(); - controller.focus(); - } - }); - } class QuickChatGlobalAction extends Action2 { diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts index 4154f8239f9..f3c7605e6e5 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts @@ -45,7 +45,7 @@ import { IChatEditingService, WorkingSetEntryState } from '../../chat/common/cha import { ChatModel, ChatRequestRemovalReason, IChatRequestModel, IChatTextEditGroup, IChatTextEditGroupState, IResponse } from '../../chat/common/chatModel.js'; import { IChatService } from '../../chat/common/chatService.js'; import { INotebookEditorService } from '../../notebook/browser/services/notebookEditorService.js'; -import { CTX_INLINE_CHAT_EDITING, CTX_INLINE_CHAT_REQUEST_IN_PROGRESS, CTX_INLINE_CHAT_RESPONSE_TYPE, CTX_INLINE_CHAT_USER_DID_EDIT, CTX_INLINE_CHAT_VISIBLE, INLINE_CHAT_ID, InlineChatConfigKeys, InlineChatResponseType } from '../common/inlineChat.js'; +import { CTX_INLINE_CHAT_EDITING, CTX_INLINE_CHAT_REQUEST_IN_PROGRESS, CTX_INLINE_CHAT_RESPONSE_TYPE, CTX_INLINE_CHAT_VISIBLE, INLINE_CHAT_ID, InlineChatConfigKeys, InlineChatResponseType } from '../common/inlineChat.js'; import { HunkInformation, Session, StashedSession } from './inlineChatSession.js'; import { IInlineChatSessionService } from './inlineChatSessionService.js'; import { InlineChatError } from './inlineChatSessionServiceImpl.js'; @@ -110,7 +110,6 @@ export class InlineChatController implements IEditorContribution { private readonly _ctxVisible: IContextKey; private readonly _ctxEditing: IContextKey; private readonly _ctxResponseType: IContextKey; - private readonly _ctxUserDidEdit: IContextKey; private readonly _ctxRequestInProgress: IContextKey; private readonly _ctxResponse: IContextKey; @@ -146,7 +145,6 @@ export class InlineChatController implements IEditorContribution { ) { this._ctxVisible = CTX_INLINE_CHAT_VISIBLE.bindTo(contextKeyService); this._ctxEditing = CTX_INLINE_CHAT_EDITING.bindTo(contextKeyService); - this._ctxUserDidEdit = CTX_INLINE_CHAT_USER_DID_EDIT.bindTo(contextKeyService); this._ctxResponseType = CTX_INLINE_CHAT_RESPONSE_TYPE.bindTo(contextKeyService); this._ctxRequestInProgress = CTX_INLINE_CHAT_REQUEST_IN_PROGRESS.bindTo(contextKeyService); @@ -409,13 +407,9 @@ export class InlineChatController implements IEditorContribution { this._messages.fire(msg); })); - const altVersionNow = this._editor.getModel()?.getAlternativeVersionId(); this._sessionStore.add(this._editor.onDidChangeModelContent(e => { - if (!this._session?.hunkData.ignoreTextModelNChanges) { - this._ctxUserDidEdit.set(altVersionNow !== this._editor.getModel()?.getAlternativeVersionId()); - } if (this._session?.hunkData.ignoreTextModelNChanges || this._ui.value.widget.hasFocus()) { return; @@ -491,7 +485,7 @@ export class InlineChatController implements IEditorContribution { this._updatePlaceholder(); if (options.message) { - this.updateInput(options.message); + this._updateInput(options.message); aria.alert(options.message); delete options.message; this._showWidget(this._session.headless, false); @@ -888,7 +882,6 @@ export class InlineChatController implements IEditorContribution { this._sessionStore.clear(); this._ctxVisible.reset(); - this._ctxUserDidEdit.reset(); this._ui.rawValue?.hide(); @@ -969,13 +962,7 @@ export class InlineChatController implements IEditorContribution { this._ui.value.widget.placeholder = this._session?.agent.description ?? ''; } - // ---- controller API - - acceptInput() { - return this.chatWidget.acceptInput(); - } - - updateInput(text: string, selectAll = true): void { + private _updateInput(text: string, selectAll = true): void { this._ui.value.widget.chatWidget.setInput(text); if (selectAll) { @@ -984,6 +971,7 @@ export class InlineChatController implements IEditorContribution { } } + // ---- controller API arrowOut(up: boolean): void { if (this._ui.value.position && this._editor.hasModel()) { @@ -999,11 +987,6 @@ export class InlineChatController implements IEditorContribution { this._ui.value.widget.focus(); } - hasFocus(): boolean { - return this._ui.value.widget.hasFocus(); - } - - async viewInChat() { if (!this._strategy || !this._session) { return; diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController2.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController2.ts index f07c82bc154..78b47cf777d 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController2.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController2.ts @@ -232,6 +232,10 @@ export class InlineChatController2 implements IEditorContribution { markActiveController() { this._isActiveController.set(true, undefined); } + + focus() { + this._zone.rawValue?.widget.focus(); + } } export class StartSessionAction2 extends EditorAction2 { diff --git a/src/vs/workbench/contrib/inlineChat/common/inlineChat.ts b/src/vs/workbench/contrib/inlineChat/common/inlineChat.ts index 21dcf39b8d6..7215c80e416 100644 --- a/src/vs/workbench/contrib/inlineChat/common/inlineChat.ts +++ b/src/vs/workbench/contrib/inlineChat/common/inlineChat.ts @@ -82,11 +82,8 @@ export const CTX_INLINE_CHAT_RESPONSE_FOCUSED = new RawContextKey('inli export const CTX_INLINE_CHAT_EMPTY = new RawContextKey('inlineChatEmpty', false, localize('inlineChatEmpty', "Whether the interactive editor input is empty")); export const CTX_INLINE_CHAT_INNER_CURSOR_FIRST = new RawContextKey('inlineChatInnerCursorFirst', false, localize('inlineChatInnerCursorFirst', "Whether the cursor of the iteractive editor input is on the first line")); export const CTX_INLINE_CHAT_INNER_CURSOR_LAST = new RawContextKey('inlineChatInnerCursorLast', false, localize('inlineChatInnerCursorLast', "Whether the cursor of the iteractive editor input is on the last line")); -export const CTX_INLINE_CHAT_INNER_CURSOR_START = new RawContextKey('inlineChatInnerCursorStart', false, localize('inlineChatInnerCursorStart', "Whether the cursor of the iteractive editor input is on the start of the input")); -export const CTX_INLINE_CHAT_INNER_CURSOR_END = new RawContextKey('inlineChatInnerCursorEnd', false, localize('inlineChatInnerCursorEnd', "Whether the cursor of the iteractive editor input is on the end of the input")); export const CTX_INLINE_CHAT_OUTER_CURSOR_POSITION = new RawContextKey<'above' | 'below' | ''>('inlineChatOuterCursorPosition', '', localize('inlineChatOuterCursorPosition', "Whether the cursor of the outer editor is above or below the interactive editor input")); export const CTX_INLINE_CHAT_HAS_STASHED_SESSION = new RawContextKey('inlineChatHasStashedSession', false, localize('inlineChatHasStashedSession', "Whether interactive editor has kept a session for quick restore")); -export const CTX_INLINE_CHAT_USER_DID_EDIT = new RawContextKey('inlineChatUserDidEdit', undefined, localize('inlineChatUserDidEdit', "Whether the user did changes ontop of the inline chat")); export const CTX_INLINE_CHAT_CHANGE_HAS_DIFF = new RawContextKey('inlineChatChangeHasDiff', false, localize('inlineChatChangeHasDiff', "Whether the current change supports showing a diff")); export const CTX_INLINE_CHAT_CHANGE_SHOWS_DIFF = new RawContextKey('inlineChatChangeShowsDiff', false, localize('inlineChatChangeShowsDiff', "Whether the current change showing a diff")); export const CTX_INLINE_CHAT_REQUEST_IN_PROGRESS = new RawContextKey('inlineChatRequestInProgress', false, localize('inlineChatRequestInProgress', "Whether an inline chat request is currently in progress")); diff --git a/src/vs/workbench/contrib/inlineChat/electron-sandbox/inlineChatActions.ts b/src/vs/workbench/contrib/inlineChat/electron-sandbox/inlineChatActions.ts index ddf6acf9f63..cc0bb05c1dc 100644 --- a/src/vs/workbench/contrib/inlineChat/electron-sandbox/inlineChatActions.ts +++ b/src/vs/workbench/contrib/inlineChat/electron-sandbox/inlineChatActions.ts @@ -67,7 +67,7 @@ function holdForSpeech(accessor: ServicesAccessor, ctrl: InlineChatController, a holdMode.finally(() => { if (listening) { commandService.executeCommand(StopListeningAction.ID).finally(() => { - ctrl.acceptInput(); + ctrl.chatWidget.acceptInput(); }); } handle.dispose(); diff --git a/src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts b/src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts index 1e12c2c3544..44fe68ae350 100644 --- a/src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts +++ b/src/vs/workbench/contrib/inlineChat/test/browser/inlineChatController.test.ts @@ -34,7 +34,7 @@ import { IChatAccessibilityService, IChatWidget, IChatWidgetService } from '../. import { ChatAgentLocation, ChatAgentService, IChatAgentData, IChatAgentNameService, IChatAgentService } from '../../../chat/common/chatAgents.js'; import { IChatResponseViewModel } from '../../../chat/common/chatViewModel.js'; import { InlineChatController, State } from '../../browser/inlineChatController.js'; -import { CTX_INLINE_CHAT_RESPONSE_TYPE, CTX_INLINE_CHAT_USER_DID_EDIT, InlineChatConfigKeys, InlineChatResponseType } from '../../common/inlineChat.js'; +import { CTX_INLINE_CHAT_RESPONSE_TYPE, InlineChatConfigKeys, InlineChatResponseType } from '../../common/inlineChat.js'; import { TestViewsService, workbenchInstantiationService } from '../../../../test/browser/workbenchTestServices.js'; import { IExtensionService, nullExtensionDescription } from '../../../../services/extensions/common/extensions.js'; import { IChatProgress, IChatService } from '../../../chat/common/chatService.js'; @@ -331,7 +331,7 @@ suite('InlineChatController', function () { assert.deepStrictEqual(session.wholeRange.value, new Range(3, 1, 3, 3)); // initial ctrl.chatWidget.setInput('GENGEN'); - ctrl.acceptInput(); + ctrl.chatWidget.acceptInput(); assert.strictEqual(await ctrl.awaitStates([State.SHOW_REQUEST, State.WAIT_FOR_INPUT]), undefined); assert.deepStrictEqual(session.wholeRange.value, new Range(1, 1, 4, 3)); @@ -452,7 +452,6 @@ suite('InlineChatController', function () { assert.strictEqual(await p, undefined); assert.ok(model.getValue().includes('GENERATED')); - assert.strictEqual(contextKeyService.getContextKeyValue(CTX_INLINE_CHAT_USER_DID_EDIT.key), undefined); ctrl.cancelSession(); await r; assert.ok(!model.getValue().includes('GENERATED')); @@ -470,7 +469,6 @@ suite('InlineChatController', function () { assert.ok(model.getValue().includes('GENERATED')); editor.executeEdits('test', [EditOperation.insert(model.getFullModelRange().getEndPosition(), 'MANUAL')]); - assert.strictEqual(contextKeyService.getContextKeyValue(CTX_INLINE_CHAT_USER_DID_EDIT.key), true); ctrl.finishExistingSession(); await r; @@ -548,7 +546,7 @@ suite('InlineChatController', function () { // REQUEST 2 const p2 = ctrl.awaitStates([State.SHOW_REQUEST, State.WAIT_FOR_INPUT]); ctrl.chatWidget.setInput('1'); - await ctrl.acceptInput(); + await ctrl.chatWidget.acceptInput(); assert.strictEqual(await p2, undefined); assert.strictEqual(model.getValue(), 'zwei-eins-'); @@ -632,7 +630,7 @@ suite('InlineChatController', function () { // REQUEST 2 const p2 = ctrl.awaitStates([State.SHOW_REQUEST, State.WAIT_FOR_INPUT]); ctrl.chatWidget.setInput('1'); - await ctrl.acceptInput(); + await ctrl.chatWidget.acceptInput(); assert.strictEqual(await p2, undefined); assert.strictEqual(model.getValue(), 'zwei\neins\nHello\nWorld\nHello Again\nHello World\n');