Skip to content

Commit f6875c0

Browse files
authored
Chat sessions context contribution (microsoft#262208)
1 parent ef94350 commit f6875c0

File tree

2 files changed

+37
-34
lines changed

2 files changed

+37
-34
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { IChatService } from '../../common/chatService.js';
1313
import { IChatSessionsService } from '../../common/chatSessionsService.js';
1414
import { ILogService } from '../../../../../platform/log/common/log.js';
1515
import Severity from '../../../../../base/common/severity.js';
16+
import { ChatContextKeys } from '../../common/chatContextKeys.js';
1617

1718
export interface IChatSessionContext {
1819
sessionId: string;
@@ -91,7 +92,7 @@ MenuRegistry.appendMenuItem(MenuId.ChatSessionsMenu, {
9192
id: RenameChatSessionAction.id,
9293
title: localize('renameSession', "Rename")
9394
},
94-
group: '1_modification',
95+
group: 'context',
9596
order: 1,
96-
when: ContextKeyExpr.true() // Will be filtered by context menu handler
97+
when: ChatContextKeys.sessionType.isEqualTo('local')
9798
});

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

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import { defaultInputBoxStyles } from '../../../../platform/theme/browser/defaul
6565
import { createSingleCallFunction } from '../../../../base/common/functional.js';
6666
import { StandardKeyboardEvent } from '../../../../base/browser/keyboardEvent.js';
6767
import { timeout } from '../../../../base/common/async.js';
68-
import { IChatSessionContext } from './actions/chatSessionActions.js';
6968
import { KeyCode } from '../../../../base/common/keyCodes.js';
7069

7170
export const VIEWLET_ID = 'workbench.view.chat.sessions';
@@ -954,6 +953,7 @@ class SessionsViewPane extends ViewPane {
954953
@IViewsService private readonly viewsService: IViewsService,
955954
@ILogService private readonly logService: ILogService,
956955
@IProgressService private readonly progressService: IProgressService,
956+
@IMenuService private readonly menuService: IMenuService,
957957
) {
958958
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService);
959959

@@ -1215,46 +1215,48 @@ class SessionsViewPane extends ViewPane {
12151215
}
12161216

12171217
private onContextMenu(e: ITreeContextMenuEvent<IChatSessionItem | null>): void {
1218-
if (!e.element || !this.isLocalChatSessionItem(e.element)) {
1218+
if (!e.element) {
12191219
return;
12201220
}
12211221

1222-
const sessionItem = e.element as ILocalChatSessionItem;
1223-
let actualSessionId: string | undefined;
1222+
const session = e.element;
1223+
const sessionWithProvider = session as ChatSessionItemWithProvider;
12241224

1225-
// Extract the actual chat session ID based on session type
1226-
if (sessionItem.sessionType === 'editor' && sessionItem.editor instanceof ChatEditorInput) {
1227-
// For editor sessions, use the ChatEditorInput's sessionId
1228-
actualSessionId = sessionItem.editor.sessionId;
1229-
} else if (sessionItem.sessionType === 'widget' && sessionItem.widget) {
1230-
// For widget sessions, get the session ID from the model
1231-
actualSessionId = sessionItem.widget.viewModel?.model.sessionId;
1232-
}
1225+
e.browserEvent.preventDefault();
1226+
e.browserEvent.stopPropagation();
12331227

1234-
if (!actualSessionId) {
1235-
return; // Cannot rename without a valid session ID
1236-
}
1228+
// Create context overlay for this specific session item
1229+
const contextOverlay = getSessionItemContextOverlay(session, sessionWithProvider.provider);
1230+
const contextKeyService = this.contextKeyService.createOverlay(contextOverlay);
12371231

1238-
// Create context for the rename action
1239-
const context: IChatSessionContext = {
1240-
sessionId: actualSessionId,
1241-
sessionType: sessionItem.sessionType,
1242-
currentTitle: sessionItem.label,
1243-
editorInput: sessionItem.editor,
1244-
editorGroup: sessionItem.group,
1245-
widget: sessionItem.widget
1232+
// Create marshalled context for command execution (same approach as action bar)
1233+
const marshalledSession = {
1234+
session: session,
1235+
$mid: MarshalledId.ChatSessionContext
12461236
};
12471237

1248-
e.browserEvent.preventDefault();
1249-
e.browserEvent.stopPropagation();
1238+
// Create menu and get all actions
1239+
const menu = this.menuService.createMenu(MenuId.ChatSessionsMenu, contextKeyService);
1240+
const actions = menu.getActions({ arg: marshalledSession, shouldForwardArgs: true });
12501241

1251-
this.contextMenuService.showContextMenu({
1252-
menuId: MenuId.ChatSessionsMenu,
1253-
menuActionOptions: { shouldForwardArgs: true },
1254-
contextKeyService: this.contextKeyService,
1255-
getAnchor: () => e.anchor,
1256-
getActionsContext: () => context,
1257-
});
1242+
// Filter to only show actions from the 'context' group
1243+
const contextActions: any[] = [];
1244+
for (const [group, groupActions] of actions) {
1245+
if (group === 'context') {
1246+
contextActions.push(...groupActions);
1247+
}
1248+
}
1249+
1250+
menu.dispose();
1251+
1252+
// Only show context menu if there are context actions
1253+
if (contextActions.length > 0) {
1254+
this.contextMenuService.showContextMenu({
1255+
getAnchor: () => e.anchor,
1256+
getActions: () => contextActions,
1257+
getActionsContext: () => marshalledSession,
1258+
});
1259+
}
12581260
}
12591261

12601262
override focus(): void {

0 commit comments

Comments
 (0)