mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
move chat overlay into workbench grid (#240808)
* make chat editing overlay a workbench editor overlay (not just a code editor overlay), same for editor specific context key, they should not be limited to code editors
* * centralize context key handling into `chatEditoringEditorContextKeys`
* workbench chat overlay also reacts to inline chat sessions
* fix leak in code lens controller
* 💄
* make sure `EditingSessionAction` find the right widget
* add `IModifiedFileEntryNavigator` to allow change navigation from "the inside"
* remove code editor based chat overlay logic
This commit is contained in:
@@ -11,7 +11,8 @@ import { EmbeddedDiffEditorWidget } from '../../../../editor/browser/widget/diff
|
||||
import { EmbeddedCodeEditorWidget } from '../../../../editor/browser/widget/codeEditor/embeddedCodeEditorWidget.js';
|
||||
import { EditorContextKeys } from '../../../../editor/common/editorContextKeys.js';
|
||||
import { InlineChatController, InlineChatController1, InlineChatController2, InlineChatRunOptions } from './inlineChatController.js';
|
||||
import { ACTION_ACCEPT_CHANGES, CTX_INLINE_CHAT_HAS_AGENT, CTX_INLINE_CHAT_HAS_STASHED_SESSION, CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST, CTX_INLINE_CHAT_VISIBLE, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, MENU_INLINE_CHAT_WIDGET_STATUS, CTX_INLINE_CHAT_REQUEST_IN_PROGRESS, CTX_INLINE_CHAT_RESPONSE_TYPE, InlineChatResponseType, ACTION_REGENERATE_RESPONSE, ACTION_VIEW_IN_CHAT, ACTION_TOGGLE_DIFF, CTX_INLINE_CHAT_CHANGE_HAS_DIFF, CTX_INLINE_CHAT_CHANGE_SHOWS_DIFF, MENU_INLINE_CHAT_ZONE, ACTION_DISCARD_CHANGES, CTX_INLINE_CHAT_POSSIBLE, ACTION_START, CTX_INLINE_CHAT_HAS_AGENT2, CTX_HAS_SESSION } from '../common/inlineChat.js';
|
||||
import { ACTION_ACCEPT_CHANGES, CTX_INLINE_CHAT_HAS_AGENT, CTX_INLINE_CHAT_HAS_STASHED_SESSION, CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST, CTX_INLINE_CHAT_VISIBLE, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, MENU_INLINE_CHAT_WIDGET_STATUS, CTX_INLINE_CHAT_REQUEST_IN_PROGRESS, CTX_INLINE_CHAT_RESPONSE_TYPE, InlineChatResponseType, ACTION_REGENERATE_RESPONSE, ACTION_VIEW_IN_CHAT, ACTION_TOGGLE_DIFF, CTX_INLINE_CHAT_CHANGE_HAS_DIFF, CTX_INLINE_CHAT_CHANGE_SHOWS_DIFF, MENU_INLINE_CHAT_ZONE, ACTION_DISCARD_CHANGES, CTX_INLINE_CHAT_POSSIBLE, ACTION_START, CTX_INLINE_CHAT_HAS_AGENT2 } from '../common/inlineChat.js';
|
||||
import { ctxIsGlobalEditingSession, ctxRequestCount } from '../../chat/browser/chatEditing/chatEditingEditorContextKeys.js';
|
||||
import { localize, localize2 } from '../../../../nls.js';
|
||||
import { Action2, IAction2Options, MenuId } from '../../../../platform/actions/common/actions.js';
|
||||
import { ContextKeyExpr, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
|
||||
@@ -29,7 +30,7 @@ import { ChatContextKeys } from '../../chat/common/chatContextKeys.js';
|
||||
import { HunkInformation } from './inlineChatSession.js';
|
||||
import { IChatWidgetService } from '../../chat/browser/chat.js';
|
||||
import { IInlineChatSessionService } from './inlineChatSessionService.js';
|
||||
import { ctxIsGlobalEditingSession } from '../../chat/browser/chatEditing/chatEditingEditorController.js';
|
||||
|
||||
|
||||
CommandsRegistry.registerCommandAlias('interactiveEditor.start', 'inlineChat.start');
|
||||
CommandsRegistry.registerCommandAlias('interactive.acceptChanges', ACTION_ACCEPT_CHANGES);
|
||||
@@ -587,7 +588,7 @@ export class StopSessionAction2 extends AbstractInline2ChatAction {
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
primary: KeyCode.Escape,
|
||||
}, {
|
||||
when: CTX_HAS_SESSION.isEqualTo('empty'),
|
||||
when: ctxRequestCount.isEqualTo(0),
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KeyI,
|
||||
}],
|
||||
@@ -611,9 +612,8 @@ export class RevealWidget extends AbstractInline2ChatAction {
|
||||
title: localize2('reveal', "Toggle Inline Chat"),
|
||||
f1: true,
|
||||
icon: Codicon.copilot,
|
||||
precondition: ContextKeyExpr.and(
|
||||
CTX_HAS_SESSION,
|
||||
),
|
||||
precondition: ContextKeyExpr.and(ctxIsGlobalEditingSession.negate(), ContextKeyExpr.greaterEquals(ctxRequestCount.key, 1)),
|
||||
toggled: CTX_INLINE_CHAT_VISIBLE,
|
||||
keybinding: {
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
primary: KeyMod.CtrlCmd | KeyCode.KeyI
|
||||
@@ -621,7 +621,7 @@ export class RevealWidget extends AbstractInline2ChatAction {
|
||||
menu: {
|
||||
id: MenuId.ChatEditingEditorContent,
|
||||
when: ContextKeyExpr.and(
|
||||
CTX_HAS_SESSION,
|
||||
ContextKeyExpr.greaterEquals(ctxRequestCount.key, 1),
|
||||
ctxIsGlobalEditingSession.negate(),
|
||||
),
|
||||
group: 'navigate',
|
||||
|
||||
@@ -12,7 +12,7 @@ import { Emitter, Event } from '../../../../base/common/event.js';
|
||||
import { Lazy } from '../../../../base/common/lazy.js';
|
||||
import { DisposableStore, MutableDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
|
||||
import { MovingAverage } from '../../../../base/common/numbers.js';
|
||||
import { autorun, autorunWithStore, constObservable, derived, IObservable, observableFromEvent, observableSignalFromEvent, observableValue, transaction } from '../../../../base/common/observable.js';
|
||||
import { autorun, autorunWithStore, derived, IObservable, observableFromEvent, observableSignalFromEvent, observableValue, transaction } from '../../../../base/common/observable.js';
|
||||
import { isEqual } from '../../../../base/common/resources.js';
|
||||
import { StopWatch } from '../../../../base/common/stopwatch.js';
|
||||
import { assertType } from '../../../../base/common/types.js';
|
||||
@@ -39,7 +39,6 @@ import { ILogService } from '../../../../platform/log/common/log.js';
|
||||
import { IEditorService, SIDE_GROUP } from '../../../services/editor/common/editorService.js';
|
||||
import { IViewsService } from '../../../services/views/common/viewsService.js';
|
||||
import { showChatView } from '../../chat/browser/chat.js';
|
||||
import { ChatEditorOverlayController } from '../../chat/browser/chatEditing/chatEditingEditorOverlay.js';
|
||||
import { IChatWidgetLocationOptions } from '../../chat/browser/chatWidget.js';
|
||||
import { ChatAgentLocation } from '../../chat/common/chatAgents.js';
|
||||
import { ChatContextKeys } from '../../chat/common/chatContextKeys.js';
|
||||
@@ -47,7 +46,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_HAS_SESSION, CTX_INLINE_CHAT_EDITING, CTX_INLINE_CHAT_HAS_AGENT2, 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 { CTX_INLINE_CHAT_EDITING, CTX_INLINE_CHAT_HAS_AGENT2, 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 { IInlineChatSession2, IInlineChatSessionService } from './inlineChatSessionService.js';
|
||||
import { InlineChatError } from './inlineChatSessionServiceImpl.js';
|
||||
@@ -1199,7 +1198,6 @@ export class InlineChatController2 implements IEditorContribution {
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
) {
|
||||
|
||||
const ctxHasSession = CTX_HAS_SESSION.bindTo(contextKeyService);
|
||||
const ctxInlineChatVisible = CTX_INLINE_CHAT_VISIBLE.bindTo(contextKeyService);
|
||||
|
||||
this._zone = new Lazy<InlineChatZoneWidget>(() => {
|
||||
@@ -1266,12 +1264,7 @@ export class InlineChatController2 implements IEditorContribution {
|
||||
const session = this._currentSession.read(r);
|
||||
|
||||
if (!session) {
|
||||
ctxHasSession.set(undefined);
|
||||
this._isActiveController.set(false, undefined);
|
||||
} else {
|
||||
const checkRequests = () => ctxHasSession.set(session.chatModel.getRequests().length === 0 ? 'empty' : 'active');
|
||||
store.add(session.chatModel.onDidChange(checkRequests));
|
||||
checkRequests();
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -1350,30 +1343,6 @@ export class InlineChatController2 implements IEditorContribution {
|
||||
session.editingSession.getEntry(session.uri)?.autoAcceptController.get()?.cancel();
|
||||
}
|
||||
}));
|
||||
|
||||
this._store.add(autorun(r => {
|
||||
|
||||
const overlay = ChatEditorOverlayController.get(_editor)!;
|
||||
const session = this._currentSession.read(r);
|
||||
const model = editorObs.model.read(r);
|
||||
if (!session || !model) {
|
||||
overlay.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
const lastResponse = observableFromEvent(this, session.chatModel.onDidChange, () => session.chatModel.getRequests().at(-1)?.response);
|
||||
const response = lastResponse.read(r);
|
||||
|
||||
const isInProgress = response
|
||||
? observableFromEvent(this, response.onDidChange, () => !response.isComplete)
|
||||
: constObservable(false);
|
||||
|
||||
if (isInProgress.read(r)) {
|
||||
overlay.showRequest(session.editingSession);
|
||||
} else if (session.editingSession.getEntry(session.uri)?.state.get() !== WorkingSetEntryState.Modified) {
|
||||
overlay.hide();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
Reference in New Issue
Block a user