@@ -46,6 +46,8 @@ import { IMenuService, MenuId, registerAction2, Action2 } from '../../../../plat
4646import { getContextMenuActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js' ;
4747import { ICommandService } from '../../../../platform/commands/common/commands.js' ;
4848import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js' ;
49+ import { IWorkbenchContribution } from '../../../common/contributions.js' ;
50+ import { ChatConfiguration } from '../common/constants.js' ;
4951
5052export 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
59111class 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
521569registerAction2 ( class OpenChatInEditorAction extends Action2 {
522570 constructor ( ) {
0 commit comments