Skip to content

Commit d0fdcbc

Browse files
authored
Merge pull request microsoft#272576 from mjbvz/dev/mjbvz/delicious-snail
Add contribution point for chat session create menu
2 parents 3da5878 + 1f2cecf commit d0fdcbc

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ export class MenuId {
273273
static readonly ChatToolOutputResourceContext = new MenuId('ChatToolOutputResourceContext');
274274
static readonly ChatMultiDiffContext = new MenuId('ChatMultiDiffContext');
275275
static readonly ChatSessionsMenu = new MenuId('ChatSessionsMenu');
276+
static readonly ChatSessionsCreateSubMenu = new MenuId('ChatSessionsCreateSubMenu');
276277
static readonly ChatConfirmationMenu = new MenuId('ChatConfirmationMenu');
277278
static readonly AccessibleView = new MenuId('AccessibleView');
278279
static readonly MultiDiffEditorFileToolbar = new MenuId('MultiDiffEditorFileToolbar');

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

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ThemeIcon } from '../../../../base/common/themables.js';
1111
import { URI } from '../../../../base/common/uri.js';
1212
import { generateUuid } from '../../../../base/common/uuid.js';
1313
import { localize, localize2 } from '../../../../nls.js';
14-
import { Action2, MenuId, MenuRegistry, registerAction2 } from '../../../../platform/actions/common/actions.js';
14+
import { Action2, IMenuService, MenuId, MenuRegistry, registerAction2 } from '../../../../platform/actions/common/actions.js';
1515
import { ContextKeyExpr, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
1616
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
1717
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
@@ -227,6 +227,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
227227
@IChatAgentService private readonly _chatAgentService: IChatAgentService,
228228
@IExtensionService private readonly _extensionService: IExtensionService,
229229
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
230+
@IMenuService private readonly _menuService: IMenuService,
230231
) {
231232
super();
232233
this._register(extensionPoint.setHandler(extensions => {
@@ -374,22 +375,43 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
374375
}
375376

376377
private _registerMenuItems(contribution: IChatSessionsExtensionPoint): IDisposable {
377-
return MenuRegistry.appendMenuItem(MenuId.ViewTitle, {
378-
command: {
379-
id: `${NEW_CHAT_SESSION_ACTION_ID}.${contribution.type}`,
380-
title: localize('interactiveSession.openNewSessionEditor', "New {0}", contribution.displayName),
378+
// If provider registers anything for the create submenu, let it fully control the creation
379+
const contextKeyService = this._contextKeyService.createOverlay([
380+
['chatSessionType', contribution.type]
381+
]);
382+
383+
const menuActions = this._menuService.getMenuActions(MenuId.ChatSessionsCreateSubMenu, contextKeyService);
384+
if (menuActions?.length) {
385+
return MenuRegistry.appendMenuItem(MenuId.ViewTitle, {
386+
group: 'navigation',
387+
title: localize('interactiveSession.chatSessionSubMenuTitle', "Create chat session"),
381388
icon: Codicon.plus,
382-
source: {
383-
id: contribution.extensionDescription.identifier.value,
384-
title: contribution.extensionDescription.displayName || contribution.extensionDescription.name,
385-
}
386-
},
387-
group: 'navigation',
388-
order: 1,
389-
when: ContextKeyExpr.and(
390-
ContextKeyExpr.equals('view', `${AGENT_SESSIONS_VIEWLET_ID}.${contribution.type}`)
391-
),
392-
});
389+
order: 1,
390+
when: ContextKeyExpr.and(
391+
ContextKeyExpr.equals('view', `${AGENT_SESSIONS_VIEWLET_ID}.${contribution.type}`)
392+
),
393+
submenu: MenuId.ChatSessionsCreateSubMenu,
394+
isSplitButton: true
395+
});
396+
} else {
397+
// We control creation instead
398+
return MenuRegistry.appendMenuItem(MenuId.ViewTitle, {
399+
command: {
400+
id: `${NEW_CHAT_SESSION_ACTION_ID}.${contribution.type}`,
401+
title: localize('interactiveSession.openNewSessionEditor', "New {0}", contribution.displayName),
402+
icon: Codicon.plus,
403+
source: {
404+
id: contribution.extensionDescription.identifier.value,
405+
title: contribution.extensionDescription.displayName || contribution.extensionDescription.name,
406+
}
407+
},
408+
group: 'navigation',
409+
order: 1,
410+
when: ContextKeyExpr.and(
411+
ContextKeyExpr.equals('view', `${AGENT_SESSIONS_VIEWLET_ID}.${contribution.type}`)
412+
),
413+
});
414+
}
393415
}
394416

395417
private _registerCommands(contribution: IChatSessionsExtensionPoint): IDisposable {

src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsViewPane.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ export class SessionsViewPane extends ViewPane {
121121
}
122122
}
123123
}));
124+
125+
if (provider) { // TODO: Why can this be undefined?
126+
this.scopedContextKeyService.createKey('chatSessionType', provider.chatSessionType);
127+
}
124128
}
125129

126130
override shouldShowWelcome(): boolean {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,20 @@ const apiMenus: IAPIMenu[] = [
451451
proposed: 'chatParticipantPrivate'
452452
},
453453
{
454+
// TODO: rename this to something like: `chatSessions/item/inline`
454455
key: 'chat/chatSessions',
455456
id: MenuId.ChatSessionsMenu,
456457
description: localize('menus.chatSessions', "The Chat Sessions menu."),
457458
supportsSubmenus: false,
458459
proposed: 'chatSessionsProvider'
459460
},
461+
{
462+
key: 'chatSessions/newSession',
463+
id: MenuId.ChatSessionsCreateSubMenu,
464+
description: localize('menus.chatSessionsNewSession', "Menu for new chat sessions."),
465+
supportsSubmenus: false,
466+
proposed: 'chatSessionsProvider'
467+
},
460468
{
461469
key: 'chat/multiDiff/context',
462470
id: MenuId.ChatMultiDiffContext,

0 commit comments

Comments
 (0)