@@ -43,20 +43,24 @@ import { Codicon } from '../../../../base/common/codicons.js';
43
43
import { IEditorService } from '../../../services/editor/common/editorService.js' ;
44
44
import { EditorInput } from '../../../common/editor/editorInput.js' ;
45
45
import { ChatEditorInput } from './chatEditorInput.js' ;
46
+ import { IChatWidgetService , IChatWidget } from './chat.js' ;
47
+ import { ChatAgentLocation , ChatConfiguration } from '../common/constants.js' ;
46
48
import { IMenuService , MenuId , MenuRegistry } from '../../../../platform/actions/common/actions.js' ;
47
49
import { getContextMenuActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js' ;
48
50
import { ICommandService } from '../../../../platform/commands/common/commands.js' ;
49
51
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js' ;
50
52
import { IWorkbenchContribution } from '../../../common/contributions.js' ;
51
- import { ChatConfiguration } from '../common/constants.js' ;
52
53
import { MarshalledId } from '../../../../base/common/marshallingIds.js' ;
54
+ import { IViewsService } from '../../../services/views/common/viewsService.js' ;
53
55
54
56
export const VIEWLET_ID = 'workbench.view.chat.sessions' ;
55
57
56
- // Extended interface for local chat session items that includes editor information
58
+ // Extended interface for local chat session items that includes editor information or widget information
57
59
interface ILocalChatSessionItem extends IChatSessionItem {
58
- editor : EditorInput ;
59
- group : IEditorGroup ;
60
+ editor ?: EditorInput ;
61
+ group ?: IEditorGroup ;
62
+ widget ?: IChatWidget ;
63
+ sessionType : 'editor' | 'widget' ;
60
64
}
61
65
62
66
export class ChatSessionsView extends Disposable implements IWorkbenchContribution {
@@ -111,6 +115,7 @@ export class ChatSessionsView extends Disposable implements IWorkbenchContributi
111
115
112
116
// Local Chat Sessions Provider - tracks open editors as chat sessions
113
117
class LocalChatSessionsProvider extends Disposable implements IChatSessionItemProvider {
118
+ static readonly CHAT_WIDGET_VIEW_ID = 'workbench.panel.chat.view.copilot' ;
114
119
readonly chatSessionType = 'local' ;
115
120
readonly label = 'Local Chat Sessions' ;
116
121
@@ -125,11 +130,26 @@ class LocalChatSessionsProvider extends Disposable implements IChatSessionItemPr
125
130
126
131
constructor (
127
132
@IEditorGroupsService private readonly editorGroupService : IEditorGroupsService ,
133
+ @IChatWidgetService private readonly chatWidgetService : IChatWidgetService ,
128
134
) {
129
135
super ( ) ;
130
136
131
137
this . initializeCurrentEditorSet ( ) ;
132
138
this . registerEditorListeners ( ) ;
139
+ this . registerWidgetListeners ( ) ;
140
+ }
141
+
142
+ private registerWidgetListeners ( ) : void {
143
+ // Listen for new chat widgets being added/removed
144
+ this . _register ( this . chatWidgetService . onDidAddWidget ( widget => {
145
+ // Only fire for chat view instance
146
+ if ( widget . location === ChatAgentLocation . Panel &&
147
+ typeof widget . viewContext === 'object' &&
148
+ 'viewId' in widget . viewContext &&
149
+ widget . viewContext . viewId === LocalChatSessionsProvider . CHAT_WIDGET_VIEW_ID ) {
150
+ this . _onDidChange . fire ( ) ;
151
+ }
152
+ } ) ) ;
133
153
}
134
154
135
155
private initializeCurrentEditorSet ( ) : void {
@@ -231,18 +251,31 @@ class LocalChatSessionsProvider extends Disposable implements IChatSessionItemPr
231
251
} ) ;
232
252
} ) ;
233
253
234
- // Build sessions in the order specified by editorOrder
254
+ // Add chat view instance
255
+ const chatWidget = this . chatWidgetService . getWidgetsByLocations ( ChatAgentLocation . Panel )
256
+ . find ( widget => typeof widget . viewContext === 'object' && 'viewId' in widget . viewContext && widget . viewContext . viewId === LocalChatSessionsProvider . CHAT_WIDGET_VIEW_ID ) ;
257
+ if ( chatWidget ) {
258
+ sessions . push ( {
259
+ id : LocalChatSessionsProvider . CHAT_WIDGET_VIEW_ID ,
260
+ label : `Chat View` ,
261
+ iconPath : Codicon . chatSparkle ,
262
+ widget : chatWidget ,
263
+ sessionType : 'widget'
264
+ } ) ;
265
+ }
266
+
267
+ // Build editor-based sessions in the order specified by editorOrder
235
268
this . editorOrder . forEach ( ( editorKey , index ) => {
236
269
const editorInfo = editorMap . get ( editorKey ) ;
237
270
if ( editorInfo ) {
238
271
const sessionId = `local-${ editorInfo . group . id } -${ index } ` ;
239
-
240
272
sessions . push ( {
241
273
id : sessionId ,
242
274
label : editorInfo . editor . getName ( ) ,
243
275
iconPath : Codicon . commentDiscussion ,
244
276
editor : editorInfo . editor ,
245
- group : editorInfo . group
277
+ group : editorInfo . group ,
278
+ sessionType : 'editor'
246
279
} ) ;
247
280
}
248
281
} ) ;
@@ -269,7 +302,6 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer {
269
302
@IViewDescriptorService viewDescriptorService : IViewDescriptorService ,
270
303
@ILogService logService : ILogService ,
271
304
@IChatSessionsService private readonly chatSessionsService : IChatSessionsService ,
272
-
273
305
) {
274
306
super (
275
307
VIEWLET_ID ,
@@ -515,6 +547,7 @@ class SessionsViewPane extends ViewPane {
515
547
@ICommandService private readonly commandService : ICommandService ,
516
548
@IEditorService private readonly editorService : IEditorService ,
517
549
@IMenuService private readonly menuService : IMenuService ,
550
+ @IViewsService private readonly viewsService : IViewsService ,
518
551
) {
519
552
super ( options , keybindingService , contextMenuService , configurationService , contextKeyService , viewDescriptorService , instantiationService , openerService , themeService , hoverService ) ;
520
553
@@ -529,7 +562,7 @@ class SessionsViewPane extends ViewPane {
529
562
}
530
563
531
564
private isLocalChatSessionItem ( item : IChatSessionItem ) : item is ILocalChatSessionItem {
532
- return 'editor' in item && 'group' in item ;
565
+ return ( 'editor' in item && 'group' in item ) || ( 'widget' in item && 'sessionType' in item ) ;
533
566
}
534
567
535
568
protected override renderBody ( container : HTMLElement ) : void {
@@ -577,8 +610,12 @@ class SessionsViewPane extends ViewPane {
577
610
this . _register ( this . tree . onDidOpen ( async e => {
578
611
const element = e . element as IChatSessionItem & { provider : IChatSessionItemProvider } ;
579
612
if ( element && this . isLocalChatSessionItem ( element ) ) {
580
- // Open the editor
581
- await this . editorService . openEditor ( element . editor , element . group ) ;
613
+ if ( element . sessionType === 'editor' && element . editor && element . group ) {
614
+ // Open the chat editor
615
+ await this . editorService . openEditor ( element . editor , element . group ) ;
616
+ } else if ( element . sessionType === 'widget' && element . widget ) {
617
+ this . viewsService . openView ( element . id , true ) ;
618
+ }
582
619
} else {
583
620
const ckey = this . contextKeyService . createKey ( 'chatSessionType' , element . provider . chatSessionType ) ;
584
621
const actions = this . menuService . getMenuActions ( MenuId . ChatSessionsMenu , this . contextKeyService ) ;
0 commit comments