Skip to content

Commit f3e85b5

Browse files
committed
Behind setting
1 parent 19ed864 commit f3e85b5

File tree

3 files changed

+71
-20
lines changed

3 files changed

+71
-20
lines changed

src/vs/workbench/api/common/extHostChatSessions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export class ExtHostChatSessions extends Disposable implements ExtHostChatSessio
1717

1818
private readonly _proxy: Proxied<MainThreadChatSessionsShape>;
1919
private readonly _statusProviders = new Map<number, { provider: vscode.ChatSessionItemProvider; disposable: DisposableStore }>();
20-
private _nextHandle = 0;
20+
// Starting at 1, 0 is reserved for local chat session item provider
21+
private _nextHandle = 1;
2122
private _sessionMap: Map<string, vscode.ChatSessionItem> = new Map();
2223

2324
constructor(

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import { ChatCompatibilityNotifier, ChatExtensionPointHandler } from './chatPart
9494
import { ChatPasteProvidersFeature } from './chatPasteProviders.js';
9595
import { QuickChatService } from './chatQuick.js';
9696
import { ChatResponseAccessibleView } from './chatResponseAccessibleView.js';
97-
import './chatSessions.js';
97+
// import './chatSessions.js';
9898
import { ChatSetupContribution } from './chatSetup.js';
9999
import { ChatStatusBarEntry } from './chatStatus.js';
100100
import { ChatVariablesService } from './chatVariables.js';
@@ -115,6 +115,7 @@ import { ChatDynamicVariableModel } from './contrib/chatDynamicVariables.js';
115115
import { ChatAttachmentResolveService, IChatAttachmentResolveService } from './chatAttachmentResolveService.js';
116116
import { registerLanguageModelActions } from './actions/chatLanguageModelActions.js';
117117
import { PromptUrlHandler } from './promptSyntax/promptUrlHandler.js';
118+
import { ChatSessionsView } from './chatSessions.js';
118119

119120
// Register configuration
120121
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
@@ -750,6 +751,7 @@ registerWorkbenchContribution2(ChatTransferContribution.ID, ChatTransferContribu
750751
registerWorkbenchContribution2(ChatContextContributions.ID, ChatContextContributions, WorkbenchPhase.AfterRestored);
751752
registerWorkbenchContribution2(ChatResponseResourceFileSystemProvider.ID, ChatResponseResourceFileSystemProvider, WorkbenchPhase.AfterRestored);
752753
registerWorkbenchContribution2(PromptUrlHandler.ID, PromptUrlHandler, WorkbenchPhase.BlockRestore);
754+
registerWorkbenchContribution2(ChatSessionsView.ID, ChatSessionsView, WorkbenchPhase.AfterRestored);
753755

754756
registerChatActions();
755757
registerChatCopyActions();

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

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import { IMenuService, MenuId, registerAction2, Action2 } from '../../../../plat
4646
import { getContextMenuActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js';
4747
import { ICommandService } from '../../../../platform/commands/common/commands.js';
4848
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
49+
import { IWorkbenchContribution } from '../../../common/contributions.js';
50+
import { ChatConfiguration } from '../common/constants.js';
4951

5052
export const VIEWLET_ID = 'workbench.view.chat.sessions';
5153

@@ -55,6 +57,56 @@ interface ILocalChatSessionItem extends IChatSessionItem {
5557
group: IEditorGroup;
5658
}
5759

60+
export class ChatSessionsView extends Disposable implements IWorkbenchContribution {
61+
static readonly ID = 'workbench.contrib.chatSessions';
62+
63+
private isViewContainerRegistered = false;
64+
65+
constructor(
66+
@IConfigurationService private readonly configurationService: IConfigurationService,
67+
) {
68+
super();
69+
70+
// Initial check
71+
this.updateViewContainerRegistration();
72+
73+
// Listen for configuration changes
74+
this._register(this.configurationService.onDidChangeConfiguration(e => {
75+
if (e.affectsConfiguration(ChatConfiguration.AgentSessionsViewLocation)) {
76+
this.updateViewContainerRegistration();
77+
}
78+
}));
79+
}
80+
81+
private updateViewContainerRegistration(): void {
82+
const location = this.configurationService.getValue<string>(ChatConfiguration.AgentSessionsViewLocation);
83+
84+
if (location === 'view' && !this.isViewContainerRegistered) {
85+
this.registerViewContainer();
86+
} else if (location !== 'view' && this.isViewContainerRegistered) {
87+
// Note: VS Code doesn't support unregistering view containers
88+
// Once registered, they remain registered for the session
89+
// but you could hide them or make them conditional through 'when' clauses
90+
}
91+
}
92+
93+
private registerViewContainer(): void {
94+
if (this.isViewContainerRegistered) {
95+
return;
96+
}
97+
98+
Registry.as<IViewContainersRegistry>(Extensions.ViewContainersRegistry).registerViewContainer(
99+
{
100+
id: VIEWLET_ID,
101+
title: nls.localize2('chat.sessions', "Chat Sessions"),
102+
ctorDescriptor: new SyncDescriptor(ChatSessionsViewPaneContainer),
103+
hideIfEmpty: false,
104+
icon: registerIcon('chat-sessions-icon', Codicon.commentDiscussion, 'Icon for Chat Sessions View'),
105+
order: 10
106+
}, ViewContainerLocation.Sidebar);
107+
}
108+
}
109+
58110
// Local Chat Sessions Provider - tracks open editors as chat sessions
59111
class LocalChatSessionsProvider extends Disposable implements IChatSessionItemProvider {
60112
readonly chatSessionType = 'local';
@@ -170,8 +222,10 @@ class LocalChatSessionsProvider extends Disposable implements IChatSessionItemPr
170222

171223
this.editorGroupService.groups.forEach(group => {
172224
group.editors.forEach(editor => {
173-
const key = this.getEditorKey(editor, group);
174-
editorMap.set(key, { editor, group });
225+
if (editor instanceof ChatEditorInput) {
226+
const key = this.getEditorKey(editor, group);
227+
editorMap.set(key, { editor, group });
228+
}
175229
});
176230
});
177231

@@ -234,15 +288,18 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer {
234288
viewDescriptorService,
235289
logService
236290
);
237-
// Listen for provider changes and register/unregister views accordingly
238-
this._register(this.chatSessionsService.onDidChangeProviders(() => {
239-
this.updateViewRegistration();
240-
}));
241291

242292
// Create and register the local chat sessions provider
243293
this.localProvider = this._register(this.instantiationService.createInstance(LocalChatSessionsProvider));
244294
this._register(this.chatSessionsService.registerChatSessionItemProvider(0, this.localProvider));
245295

296+
this.updateViewRegistration();
297+
298+
// Listen for provider changes and register/unregister views accordingly
299+
this._register(this.chatSessionsService.onDidChangeProviders(() => {
300+
this.updateViewRegistration();
301+
}));
302+
246303
}
247304

248305
override getTitle(): string {
@@ -261,7 +318,8 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer {
261318
const providers = this.chatSessionsService.providers;
262319
const viewDescriptors: IViewDescriptor[] = [];
263320
if (container && providers.length > 0) {
264-
providers.forEach((provider, index) => {
321+
let index = 1;
322+
providers.forEach(provider => {
265323
viewDescriptors.push({
266324
id: `${VIEWLET_ID}.${provider.chatSessionType}`,
267325
// TODO: localization?
@@ -272,7 +330,7 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer {
272330
ctorDescriptor: new SyncDescriptor(SessionsViewPane, [provider]),
273331
canToggleVisibility: true,
274332
canMoveView: true,
275-
order: index,
333+
order: provider.chatSessionType === 'local' ? 0 : index++,
276334
});
277335
});
278336
Registry.as<IViewsRegistry>(Extensions.ViewsRegistry).registerViews(viewDescriptors, container);
@@ -507,16 +565,6 @@ class SessionsViewPane extends ViewPane {
507565
}
508566
}
509567

510-
Registry.as<IViewContainersRegistry>(Extensions.ViewContainersRegistry).registerViewContainer(
511-
{
512-
id: VIEWLET_ID,
513-
title: nls.localize2('chat.sessions', "Chat Sessions"),
514-
ctorDescriptor: new SyncDescriptor(ChatSessionsViewPaneContainer),
515-
hideIfEmpty: false,
516-
icon: registerIcon('chat-sessions-icon', Codicon.commentDiscussion, 'Icon for Chat Sessions View'),
517-
order: 10
518-
}, ViewContainerLocation.Sidebar);
519-
520568
// Register action for "Open in Editor" command in Local Chat Sessions view
521569
registerAction2(class OpenChatInEditorAction extends Action2 {
522570
constructor() {

0 commit comments

Comments
 (0)