Skip to content

Commit 67a93b0

Browse files
authored
Revert "Revert "chat command center polish (microsoft#229674)" (microsoft#229755)" (microsoft#229802)
This reverts commit 11fb5bb. Add another context key `inlineChatPossible` which truely checks code editors so that a global command works
1 parent a45ae99 commit 67a93b0

File tree

7 files changed

+56
-13
lines changed

7 files changed

+56
-13
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,5 @@
170170
},
171171
"css.format.spaceAroundSelectorSeparator": true,
172172
"typescript.enablePromptUseWorkspaceTsdk": true,
173-
"inlineChat.experimental.onlyZoneWidget": true
173+
"chat.commandCenter.enabled": true
174174
}

src/vs/platform/actions/browser/dropdownWithPrimaryActionViewItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class DropdownWithPrimaryActionViewItem extends BaseActionViewItem {
6161
menuAsChild: _options?.menuAsChild ?? true,
6262
classNames: className ? ['codicon', 'codicon-chevron-down', className] : ['codicon', 'codicon-chevron-down'],
6363
actionRunner: this._options?.actionRunner,
64-
keybindingProvider: this._options?.getKeyBinding,
64+
keybindingProvider: this._options?.getKeyBinding ?? (action => _keybindingService.lookupKeybinding(action.id)),
6565
hoverDelegate: _options?.hoverDelegate
6666
});
6767
}

src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class QuickChatGlobalAction extends Action2 {
116116
},
117117
menu: {
118118
id: MenuId.ChatCommandCenter,
119-
group: 'open',
119+
group: 'c_quickChat',
120120
order: 5
121121
},
122122
metadata: {

src/vs/workbench/contrib/chat/browser/chat.contribution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ configurationRegistry.registerConfiguration({
103103
},
104104
'chat.commandCenter.enabled': {
105105
type: 'boolean',
106+
tags: ['experimental'],
106107
markdownDescription: nls.localize('chat.commandCenter.enabled', "Controls whether the command center shows a menu for chat actions (requires {0}).", '`#window.commandCenter#`'),
107-
default: true
108+
default: false
108109
},
109110
'chat.experimental.implicitContext': {
110111
type: 'boolean',

src/vs/workbench/contrib/inlineChat/browser/inlineChatActions.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { EmbeddedDiffEditorWidget } from '../../../../editor/browser/widget/diff
1111
import { EmbeddedCodeEditorWidget } from '../../../../editor/browser/widget/codeEditor/embeddedCodeEditorWidget.js';
1212
import { EditorContextKeys } from '../../../../editor/common/editorContextKeys.js';
1313
import { InlineChatController, InlineChatRunOptions } from './inlineChatController.js';
14-
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, CTX_INLINE_CHAT_USER_DID_EDIT, CTX_INLINE_CHAT_DOCUMENT_CHANGED, CTX_INLINE_CHAT_EDIT_MODE, EditMode, 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 } from '../common/inlineChat.js';
14+
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, CTX_INLINE_CHAT_USER_DID_EDIT, CTX_INLINE_CHAT_DOCUMENT_CHANGED, CTX_INLINE_CHAT_EDIT_MODE, EditMode, 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 } from '../common/inlineChat.js';
1515
import { localize, localize2 } from '../../../../nls.js';
16-
import { Action2, IAction2Options } from '../../../../platform/actions/common/actions.js';
16+
import { Action2, IAction2Options, MenuId } from '../../../../platform/actions/common/actions.js';
1717
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
1818
import { IInstantiationService, ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
1919
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
@@ -49,17 +49,26 @@ export class StartSessionAction extends EditorAction2 {
4949
constructor() {
5050
super({
5151
id: 'inlineChat.start',
52-
title: localize2('run', 'Editor Chat'),
52+
title: localize2('run', 'Editor Inline Chat'),
5353
category: AbstractInlineChatAction.category,
5454
f1: true,
55-
precondition: ContextKeyExpr.and(CTX_INLINE_CHAT_HAS_AGENT, EditorContextKeys.writable),
55+
precondition: ContextKeyExpr.and(
56+
CTX_INLINE_CHAT_HAS_AGENT,
57+
CTX_INLINE_CHAT_POSSIBLE,
58+
EditorContextKeys.writable
59+
),
5660
keybinding: {
5761
when: EditorContextKeys.focus,
5862
weight: KeybindingWeight.WorkbenchContrib,
5963
primary: KeyMod.CtrlCmd | KeyCode.KeyI,
6064
secondary: [KeyChord(KeyMod.CtrlCmd | KeyCode.KeyK, KeyCode.KeyI)],
6165
},
62-
icon: START_INLINE_CHAT
66+
icon: START_INLINE_CHAT,
67+
menu: {
68+
id: MenuId.ChatCommandCenter,
69+
group: 'b_inlineChat',
70+
order: 10,
71+
}
6372
});
6473
}
6574

src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55
import { CancellationToken } from '../../../../base/common/cancellation.js';
66
import { Emitter, Event } from '../../../../base/common/event.js';
7-
import { DisposableStore, IDisposable, MutableDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
7+
import { DisposableMap, DisposableStore, IDisposable, MutableDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
88
import { Schemas } from '../../../../base/common/network.js';
99
import { URI } from '../../../../base/common/uri.js';
1010
import { generateUuid } from '../../../../base/common/uuid.js';
@@ -22,14 +22,16 @@ import { ITelemetryService } from '../../../../platform/telemetry/common/telemet
2222
import { DEFAULT_EDITOR_ASSOCIATION } from '../../../common/editor.js';
2323
import { ChatAgentLocation, IChatAgentService } from '../../chat/common/chatAgents.js';
2424
import { IChatService } from '../../chat/common/chatService.js';
25-
import { CTX_INLINE_CHAT_HAS_AGENT, EditMode } from '../common/inlineChat.js';
25+
import { CTX_INLINE_CHAT_HAS_AGENT, CTX_INLINE_CHAT_POSSIBLE, EditMode, INLINE_CHAT_ID } from '../common/inlineChat.js';
2626
import { IEditorService } from '../../../services/editor/common/editorService.js';
2727
import { UntitledTextEditorInput } from '../../../services/untitled/common/untitledTextEditorInput.js';
2828
import { HunkData, Session, SessionWholeRange, StashedSession, TelemetryData, TelemetryDataClassification } from './inlineChatSession.js';
2929
import { IInlineChatSessionEndEvent, IInlineChatSessionEvent, IInlineChatSessionService, ISessionKeyComputer } from './inlineChatSessionService.js';
3030
import { isEqual } from '../../../../base/common/resources.js';
3131
import { ILanguageService } from '../../../../editor/common/languages/language.js';
3232
import { ITextFileService } from '../../../services/textfile/common/textfiles.js';
33+
import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js';
34+
import { EditorOption } from '../../../../editor/common/config/editorOptions.js';
3335

3436

3537
type SessionData = {
@@ -319,21 +321,51 @@ export class InlineChatEnabler {
319321
static Id = 'inlineChat.enabler';
320322

321323
private readonly _ctxHasProvider: IContextKey<boolean>;
324+
private readonly _ctxPossible: IContextKey<boolean>;
322325

323326
private readonly _store = new DisposableStore();
324327

325328
constructor(
326329
@IContextKeyService contextKeyService: IContextKeyService,
327-
@IChatAgentService chatAgentService: IChatAgentService
330+
@IChatAgentService chatAgentService: IChatAgentService,
331+
@ICodeEditorService codeEditorService: ICodeEditorService,
332+
@IEditorService editorService: IEditorService,
328333
) {
329334
this._ctxHasProvider = CTX_INLINE_CHAT_HAS_AGENT.bindTo(contextKeyService);
330-
this._store.add(chatAgentService.onDidChangeAgents(() => {
335+
this._ctxPossible = CTX_INLINE_CHAT_POSSIBLE.bindTo(contextKeyService);
336+
337+
const updateAgent = () => {
331338
const hasEditorAgent = Boolean(chatAgentService.getDefaultAgent(ChatAgentLocation.Editor));
332339
this._ctxHasProvider.set(hasEditorAgent);
340+
};
341+
342+
this._store.add(chatAgentService.onDidChangeAgents(updateAgent));
343+
updateAgent();
344+
345+
const updateEditor = () => {
346+
const editor = codeEditorService.getFocusedCodeEditor() ?? codeEditorService.getActiveCodeEditor();
347+
348+
this._ctxPossible.set(Boolean(editor
349+
&& editor.getContribution(INLINE_CHAT_ID)
350+
&& editor.hasWidgetFocus()
351+
&& !editor.getOption(EditorOption.readOnly)
352+
&& !editor.isSimpleWidget
353+
));
354+
};
355+
356+
this._store.add(editorService.onDidActiveEditorChange(updateEditor));
357+
358+
const editorDisposables = this._store.add(new DisposableMap<ICodeEditor>());
359+
this._store.add(codeEditorService.onCodeEditorAdd(e => {
360+
editorDisposables.set(e, Event.any(e.onDidBlurEditorWidget, e.onDidFocusEditorWidget)(updateEditor));
361+
}));
362+
this._store.add(codeEditorService.onCodeEditorRemove(e => {
363+
editorDisposables.deleteAndDispose(e);
333364
}));
334365
}
335366

336367
dispose() {
368+
this._ctxPossible.reset();
337369
this._ctxHasProvider.reset();
338370
this._store.dispose();
339371
}

src/vs/workbench/contrib/inlineChat/common/inlineChat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const enum InlineChatResponseType {
8888
MessagesAndEdits = 'messagesAndEdits'
8989
}
9090

91+
export const CTX_INLINE_CHAT_POSSIBLE = new RawContextKey<boolean>('inlineChatPossible', false, localize('inlineChatHasPossible', "Whether a provider for inline chat exists and whether an editor for inline chat is open"));
9192
export const CTX_INLINE_CHAT_HAS_AGENT = new RawContextKey<boolean>('inlineChatHasProvider', false, localize('inlineChatHasProvider', "Whether a provider for interactive editors exists"));
9293
export const CTX_INLINE_CHAT_VISIBLE = new RawContextKey<boolean>('inlineChatVisible', false, localize('inlineChatVisible', "Whether the interactive editor input is visible"));
9394
export const CTX_INLINE_CHAT_FOCUSED = new RawContextKey<boolean>('inlineChatFocused', false, localize('inlineChatFocused', "Whether the interactive editor input is focused"));

0 commit comments

Comments
 (0)