@@ -43,20 +43,24 @@ import { Codicon } from '../../../../base/common/codicons.js';
4343import { IEditorService } from '../../../services/editor/common/editorService.js' ;
4444import { EditorInput } from '../../../common/editor/editorInput.js' ;
4545import { ChatEditorInput } from './chatEditorInput.js' ;
46+ import { IChatWidgetService , IChatWidget } from './chat.js' ;
47+ import { ChatAgentLocation , ChatConfiguration } from '../common/constants.js' ;
4648import { IMenuService , MenuId , MenuRegistry } from '../../../../platform/actions/common/actions.js' ;
4749import { getContextMenuActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js' ;
4850import { ICommandService } from '../../../../platform/commands/common/commands.js' ;
4951import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js' ;
5052import { IWorkbenchContribution } from '../../../common/contributions.js' ;
51- import { ChatConfiguration } from '../common/constants.js' ;
5253import { MarshalledId } from '../../../../base/common/marshallingIds.js' ;
54+ import { IViewsService } from '../../../services/views/common/viewsService.js' ;
5355
5456export const VIEWLET_ID = 'workbench.view.chat.sessions' ;
5557
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
5759interface ILocalChatSessionItem extends IChatSessionItem {
58- editor : EditorInput ;
59- group : IEditorGroup ;
60+ editor ?: EditorInput ;
61+ group ?: IEditorGroup ;
62+ widget ?: IChatWidget ;
63+ sessionType : 'editor' | 'widget' ;
6064}
6165
6266export class ChatSessionsView extends Disposable implements IWorkbenchContribution {
@@ -111,6 +115,7 @@ export class ChatSessionsView extends Disposable implements IWorkbenchContributi
111115
112116// Local Chat Sessions Provider - tracks open editors as chat sessions
113117class LocalChatSessionsProvider extends Disposable implements IChatSessionItemProvider {
118+ static readonly CHAT_WIDGET_VIEW_ID = 'workbench.panel.chat.view.copilot' ;
114119 readonly chatSessionType = 'local' ;
115120 readonly label = 'Local Chat Sessions' ;
116121
@@ -125,11 +130,26 @@ class LocalChatSessionsProvider extends Disposable implements IChatSessionItemPr
125130
126131 constructor (
127132 @IEditorGroupsService private readonly editorGroupService : IEditorGroupsService ,
133+ @IChatWidgetService private readonly chatWidgetService : IChatWidgetService ,
128134 ) {
129135 super ( ) ;
130136
131137 this . initializeCurrentEditorSet ( ) ;
132138 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+ } ) ) ;
133153 }
134154
135155 private initializeCurrentEditorSet ( ) : void {
@@ -231,18 +251,31 @@ class LocalChatSessionsProvider extends Disposable implements IChatSessionItemPr
231251 } ) ;
232252 } ) ;
233253
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
235268 this . editorOrder . forEach ( ( editorKey , index ) => {
236269 const editorInfo = editorMap . get ( editorKey ) ;
237270 if ( editorInfo ) {
238271 const sessionId = `local-${ editorInfo . group . id } -${ index } ` ;
239-
240272 sessions . push ( {
241273 id : sessionId ,
242274 label : editorInfo . editor . getName ( ) ,
243275 iconPath : Codicon . commentDiscussion ,
244276 editor : editorInfo . editor ,
245- group : editorInfo . group
277+ group : editorInfo . group ,
278+ sessionType : 'editor'
246279 } ) ;
247280 }
248281 } ) ;
@@ -269,7 +302,6 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer {
269302 @IViewDescriptorService viewDescriptorService : IViewDescriptorService ,
270303 @ILogService logService : ILogService ,
271304 @IChatSessionsService private readonly chatSessionsService : IChatSessionsService ,
272-
273305 ) {
274306 super (
275307 VIEWLET_ID ,
@@ -515,6 +547,7 @@ class SessionsViewPane extends ViewPane {
515547 @ICommandService private readonly commandService : ICommandService ,
516548 @IEditorService private readonly editorService : IEditorService ,
517549 @IMenuService private readonly menuService : IMenuService ,
550+ @IViewsService private readonly viewsService : IViewsService ,
518551 ) {
519552 super ( options , keybindingService , contextMenuService , configurationService , contextKeyService , viewDescriptorService , instantiationService , openerService , themeService , hoverService ) ;
520553
@@ -529,7 +562,7 @@ class SessionsViewPane extends ViewPane {
529562 }
530563
531564 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 ) ;
533566 }
534567
535568 protected override renderBody ( container : HTMLElement ) : void {
@@ -577,8 +610,12 @@ class SessionsViewPane extends ViewPane {
577610 this . _register ( this . tree . onDidOpen ( async e => {
578611 const element = e . element as IChatSessionItem & { provider : IChatSessionItemProvider } ;
579612 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+ }
582619 } else {
583620 const ckey = this . contextKeyService . createKey ( 'chatSessionType' , element . provider . chatSessionType ) ;
584621 const actions = this . menuService . getMenuActions ( MenuId . ChatSessionsMenu , this . contextKeyService ) ;
0 commit comments