Skip to content

Commit a0f95f9

Browse files
committed
Add contribution point for chat session create menu
This allows extension to contribute to a special split button for creating chat sessions. Currently this is shown in the title of each chat session view, but if we unify the sessions view we would likely move it to the panel title
1 parent 5d91fa2 commit a0f95f9

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';
@@ -222,6 +222,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
222222
@IChatAgentService private readonly _chatAgentService: IChatAgentService,
223223
@IExtensionService private readonly _extensionService: IExtensionService,
224224
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
225+
@IMenuService private readonly _menuService: IMenuService,
225226
) {
226227
super();
227228
this._register(extensionPoint.setHandler(extensions => {
@@ -368,22 +369,43 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
368369
}
369370

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

389411
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)