Skip to content

Commit ce8f8ed

Browse files
authored
Cleanup menus that have chat context specific actions (fix microsoft#255320) (microsoft#255618)
1 parent 09a342a commit ce8f8ed

File tree

7 files changed

+36
-41
lines changed

7 files changed

+36
-41
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
// --- Chat ---
3-
"inlineChat.enableV2": true,
3+
// "inlineChat.enableV2": true,
44

55
// --- Editor ---
66
"editor.insertSpaces": false,

src/vs/platform/actions/common/actions.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export class MenuId {
128128
static readonly SCMSourceControlTitle = new MenuId('SCMSourceControlTitle');
129129
static readonly SCMHistoryTitle = new MenuId('SCMHistoryTitle');
130130
static readonly SCMHistoryItemContext = new MenuId('SCMHistoryItemContext');
131-
static readonly SCMHistoryItemChatContext = new MenuId('SCMHistoryItemChatContext');
132131
static readonly SCMHistoryItemChangeContext = new MenuId('SCMHistoryItemChangeContext');
133132
static readonly SCMHistoryItemHover = new MenuId('SCMHistoryItemHover');
134133
static readonly SCMHistoryItemRefContext = new MenuId('SCMHistoryItemRefContext');
@@ -252,7 +251,6 @@ export class MenuId {
252251
static readonly ChatTitleBarMenu = new MenuId('ChatTitleBarMenu');
253252
static readonly ChatAttachmentsContext = new MenuId('ChatAttachmentsContext');
254253
static readonly ChatToolOutputResourceToolbar = new MenuId('ChatToolOutputResourceToolbar');
255-
static readonly ChatExplorerMenu = new MenuId('ChatExplorerMenu');
256254
static readonly ChatTextEditorMenu = new MenuId('ChatTextEditorMenu');
257255
static readonly ChatTerminalMenu = new MenuId('ChatTerminalMenu');
258256
static readonly ChatToolOutputResourceContext = new MenuId('ChatToolOutputResourceContext');

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,14 +1090,8 @@ const title = localize('ai actions', "AI Actions");
10901090

10911091
MenuRegistry.appendMenuItem(MenuId.EditorContext, {
10921092
submenu: MenuId.ChatTextEditorMenu,
1093-
group: '1_copilot',
1094-
title,
1095-
when: menuContext
1096-
});
1097-
1098-
MenuRegistry.appendMenuItem(MenuId.ExplorerContext, {
1099-
submenu: MenuId.ChatExplorerMenu,
1100-
group: '5_copilot',
1093+
group: '1_chat',
1094+
order: 3,
11011095
title,
11021096
when: menuContext
11031097
});

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ import { IFileService } from '../../../../../platform/files/common/files.js';
2525
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
2626
import { IKeybindingService } from '../../../../../platform/keybinding/common/keybinding.js';
2727
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
28+
import { IListService } from '../../../../../platform/list/browser/listService.js';
2829
import { ILogService } from '../../../../../platform/log/common/log.js';
2930
import { AnythingQuickAccessProviderRunOptions } from '../../../../../platform/quickinput/common/quickAccess.js';
3031
import { IQuickInputService, IQuickPickItem, IQuickPickItemWithResource, QuickPickItem } from '../../../../../platform/quickinput/common/quickInput.js';
32+
import { resolveCommandsContext } from '../../../../browser/parts/editor/editorCommandsContext.js';
3133
import { ResourceContextKey } from '../../../../common/contextkeys.js';
32-
import { EditorResourceAccessor, SideBySideEditor } from '../../../../common/editor.js';
34+
import { EditorResourceAccessor, isEditorCommandsContext, SideBySideEditor } from '../../../../common/editor.js';
35+
import { IEditorGroupsService } from '../../../../services/editor/common/editorGroupsService.js';
3336
import { IEditorService } from '../../../../services/editor/common/editorService.js';
3437
import { IViewsService } from '../../../../services/views/common/viewsService.js';
3538
import { ExplorerFolderContext } from '../../../files/common/files.js';
@@ -82,7 +85,7 @@ abstract class AttachResourceAction extends Action2 {
8285
protected _getResources(accessor: ServicesAccessor, ...args: any[]): URI[] {
8386
const editorService = accessor.get(IEditorService);
8487

85-
const contexts = Array.isArray(args[1]) ? args[1] : [args[0]];
88+
const contexts = isEditorCommandsContext(args[1]) ? this._getEditorResources(accessor, args) : Array.isArray(args[1]) ? args[1] : [args[0]];
8689
const files = [];
8790
for (const context of contexts) {
8891
let uri;
@@ -103,6 +106,15 @@ abstract class AttachResourceAction extends Action2 {
103106

104107
return files;
105108
}
109+
110+
private _getEditorResources(accessor: ServicesAccessor, ...args: any[]): URI[] {
111+
const resolvedContext = resolveCommandsContext(args, accessor.get(IEditorService), accessor.get(IEditorGroupsService), accessor.get(IListService));
112+
113+
return resolvedContext.groupedEditors
114+
.flatMap(groupedEditor => groupedEditor.editors)
115+
.map(editor => EditorResourceAccessor.getCanonicalUri(editor, { supportSideBySide: SideBySideEditor.PRIMARY }))
116+
.filter(uri => uri !== undefined);
117+
}
106118
}
107119

108120
class AttachFileToChatAction extends AttachResourceAction {
@@ -122,8 +134,8 @@ class AttachFileToChatAction extends AttachResourceAction {
122134
order: 1,
123135
when: ContextKeyExpr.and(ChatContextKeys.enabled, SearchContext.FileMatchOrMatchFocusKey, SearchContext.SearchResultHeaderFocused.negate()),
124136
}, {
125-
id: MenuId.ChatExplorerMenu,
126-
group: 'zContext',
137+
id: MenuId.ExplorerContext,
138+
group: '5_chat',
127139
order: 1,
128140
when: ContextKeyExpr.and(
129141
ChatContextKeys.enabled,
@@ -135,7 +147,7 @@ class AttachFileToChatAction extends AttachResourceAction {
135147
),
136148
}, {
137149
id: MenuId.EditorTitleContext,
138-
group: 'zContext',
150+
group: '2_chat',
139151
order: 1,
140152
when: ContextKeyExpr.and(
141153
ChatContextKeys.enabled,
@@ -145,8 +157,8 @@ class AttachFileToChatAction extends AttachResourceAction {
145157
)
146158
),
147159
}, {
148-
id: MenuId.ChatTextEditorMenu,
149-
group: 'zContext',
160+
id: MenuId.EditorContext,
161+
group: '1_chat',
150162
order: 2,
151163
when: ContextKeyExpr.and(
152164
ChatContextKeys.enabled,
@@ -186,8 +198,8 @@ class AttachFolderToChatAction extends AttachResourceAction {
186198
category: CHAT_CATEGORY,
187199
f1: false,
188200
menu: {
189-
id: MenuId.ChatExplorerMenu,
190-
group: 'zContext',
201+
id: MenuId.ExplorerContext,
202+
group: '5_chat',
191203
order: 1,
192204
when: ContextKeyExpr.and(
193205
ChatContextKeys.enabled,
@@ -227,8 +239,8 @@ class AttachSelectionToChatAction extends Action2 {
227239
f1: true,
228240
precondition: ChatContextKeys.enabled,
229241
menu: {
230-
id: MenuId.ChatTextEditorMenu,
231-
group: 'zContext',
242+
id: MenuId.EditorContext,
243+
group: '1_chat',
232244
order: 1,
233245
when: ContextKeyExpr.and(
234246
ChatContextKeys.enabled,

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,6 @@ MenuRegistry.appendMenuItem(MenuId.EditorLineNumberContext, {
642642
group: '9_quickDiffDecorations'
643643
});
644644

645-
MenuRegistry.appendMenuItem(MenuId.SCMHistoryItemContext, {
646-
title: localize('scmHistoryItemChatContext', "Copilot"),
647-
submenu: MenuId.SCMHistoryItemChatContext,
648-
group: '8_chat'
649-
});
650-
651645
registerSingleton(ISCMService, SCMService, InstantiationType.Delayed);
652646
registerSingleton(ISCMViewService, SCMViewService, InstantiationType.Delayed);
653647
registerSingleton(IQuickDiffService, QuickDiffService, InstantiationType.Delayed);

src/vs/workbench/contrib/scm/browser/scmHistoryChatContext.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,13 @@ registerAction2(class extends Action2 {
165165
constructor() {
166166
super({
167167
id: 'workbench.scm.action.graph.addHistoryItemToChat',
168-
title: localize('chat.action.scmHistoryItemContext', 'Add History Item to Chat'),
168+
title: localize('chat.action.scmHistoryItemContext', 'Add to Chat'),
169169
f1: false,
170170
menu: {
171-
id: MenuId.SCMHistoryItemChatContext,
172-
when: ChatContextKeys.Setup.installed
171+
id: MenuId.SCMHistoryItemContext,
172+
group: 'z_chat',
173+
order: 1,
174+
when: ChatContextKeys.enabled
173175
}
174176
});
175177
}
@@ -189,11 +191,13 @@ registerAction2(class extends Action2 {
189191
constructor() {
190192
super({
191193
id: 'workbench.scm.action.graph.summarizeHistoryItem',
192-
title: localize('chat.action.scmHistoryItemSummarize', 'Summarize History Item'),
194+
title: localize('chat.action.scmHistoryItemSummarize', 'Explain Changes'),
193195
f1: false,
194196
menu: {
195-
id: MenuId.SCMHistoryItemChatContext,
196-
when: ChatContextKeys.Setup.installed
197+
id: MenuId.SCMHistoryItemContext,
198+
group: 'z_chat',
199+
order: 2,
200+
when: ChatContextKeys.enabled
197201
}
198202
});
199203
}

src/vs/workbench/services/actions/common/menusExtensionPoint.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,6 @@ const apiMenus: IAPIMenu[] = [
451451
supportsSubmenus: false,
452452
proposed: 'chatParticipantPrivate'
453453
},
454-
{
455-
key: 'explorer/context/chat',
456-
id: MenuId.ChatExplorerMenu,
457-
description: localize('menus.chatExplorer', "The Chat submenu in the explorer context menu."),
458-
supportsSubmenus: false,
459-
proposed: 'chatParticipantPrivate'
460-
},
461454
{
462455
key: 'editor/context/chat',
463456
id: MenuId.ChatTextEditorMenu,

0 commit comments

Comments
 (0)