diff --git a/src/vs/workbench/contrib/chat/browser/chatSessions/localChatSessionsProvider.ts b/src/vs/workbench/contrib/chat/browser/chatSessions/localChatSessionsProvider.ts index 0fdf2bfff95..49d15b98189 100644 --- a/src/vs/workbench/contrib/chat/browser/chatSessions/localChatSessionsProvider.ts +++ b/src/vs/workbench/contrib/chat/browser/chatSessions/localChatSessionsProvider.ts @@ -74,20 +74,7 @@ export class LocalChatSessionsProvider extends Disposable implements IChatSessio 'viewId' in widget.viewContext && widget.viewContext.viewId === LocalChatSessionsProvider.CHAT_WIDGET_VIEW_ID) { this._onDidChange.fire(); - - // Listen for view model changes on this widget - this._register(widget.onDidChangeViewModel(() => { - this._onDidChange.fire(); - if (widget.viewModel) { - this.registerProgressListener(widget.viewModel.model.requestInProgressObs); - } - })); - - // Listen for title changes on the current model - this.registerModelTitleListener(widget); - if (widget.viewModel) { - this.registerProgressListener(widget.viewModel.model.requestInProgressObs); - } + this._registerWidgetModelListeners(widget); } })); @@ -96,19 +83,25 @@ export class LocalChatSessionsProvider extends Disposable implements IChatSessio .filter(widget => typeof widget.viewContext === 'object' && 'viewId' in widget.viewContext && widget.viewContext.viewId === LocalChatSessionsProvider.CHAT_WIDGET_VIEW_ID); existingWidgets.forEach(widget => { - this._register(widget.onDidChangeViewModel(() => { - this._onDidChange.fire(); - this.registerModelTitleListener(widget); - })); + this._registerWidgetModelListeners(widget); + }); + } - // Register title listener for existing widget + private _registerWidgetModelListeners(widget: IChatWidget): void { + const register = () => { this.registerModelTitleListener(widget); if (widget.viewModel) { this.registerProgressListener(widget.viewModel.model.requestInProgressObs); } - }); - } + }; + // Listen for view model changes on this widget + this._register(widget.onDidChangeViewModel(() => { + register(); + this._onDidChangeChatSessionItems.fire(); + })); + register(); + } private registerProgressListener(observable: IObservable) { const progressEvent = Event.fromObservableLight(observable); this._register(progressEvent(() => { diff --git a/src/vs/workbench/contrib/chat/browser/chatSessions/view/chatSessionsView.ts b/src/vs/workbench/contrib/chat/browser/chatSessions/view/chatSessionsView.ts index c4e77c2648b..20633da2090 100644 --- a/src/vs/workbench/contrib/chat/browser/chatSessions/view/chatSessionsView.ts +++ b/src/vs/workbench/contrib/chat/browser/chatSessions/view/chatSessionsView.ts @@ -258,7 +258,6 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer { @IWorkspaceContextService contextService: IWorkspaceContextService, @IViewDescriptorService viewDescriptorService: IViewDescriptorService, @ILogService logService: ILogService, - @IChatSessionsService private readonly chatSessionsService: IChatSessionsService, ) { super( AGENT_SESSIONS_VIEWLET_ID, @@ -277,30 +276,10 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer { viewDescriptorService, logService ); - - // Listen for session items changes and refresh the appropriate provider tree - this._register(this.chatSessionsService.onDidChangeSessionItems((chatSessionType) => { - this.refreshProviderTree(chatSessionType); - })); } override getTitle(): string { const title = nls.localize('chat.agent.sessions.title', "Agent Sessions"); return title; } - - private refreshProviderTree(chatSessionType: string): void { - // Find the provider with the matching chatSessionType - const providers = Array.from(this.chatSessionsService.getAllChatSessionItemProviders()); - const targetProvider = providers.find(provider => provider.chatSessionType === chatSessionType); - - if (targetProvider) { - // Find the corresponding view and refresh its tree - const viewId = `${AGENT_SESSIONS_VIEWLET_ID}.${chatSessionType}`; - const view = this.getView(viewId) as SessionsViewPane | undefined; - if (view) { - view.refreshTree(); - } - } - } } diff --git a/src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsViewPane.ts b/src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsViewPane.ts index 98ff37868ba..2fc23a38e6d 100644 --- a/src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsViewPane.ts +++ b/src/vs/workbench/contrib/chat/browser/chatSessions/view/sessionsViewPane.ts @@ -39,7 +39,7 @@ import { IEditorGroupsService } from '../../../../../services/editor/common/edit import { IEditorService } from '../../../../../services/editor/common/editorService.js'; import { IViewsService } from '../../../../../services/views/common/viewsService.js'; import { IChatService } from '../../../common/chatService.js'; -import { IChatSessionItemProvider, localChatSessionType } from '../../../common/chatSessionsService.js'; +import { IChatSessionItemProvider, IChatSessionsService, localChatSessionType } from '../../../common/chatSessionsService.js'; import { ChatConfiguration, ChatEditorTitleMaxLength } from '../../../common/constants.js'; import { ACTION_ID_OPEN_CHAT } from '../../actions/chatActions.js'; import { ChatViewId, IChatWidgetService } from '../../chat.js'; @@ -98,6 +98,7 @@ export class SessionsViewPane extends ViewPane { @ICommandService private readonly commandService: ICommandService, @IChatWidgetService private readonly chatWidgetService: IChatWidgetService, @IEditorGroupsService private readonly editorGroupsService: IEditorGroupsService, + @IChatSessionsService private readonly chatSessionsService: IChatSessionsService, ) { super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService); this.minimumBodySize = 44; @@ -120,6 +121,12 @@ export class SessionsViewPane extends ViewPane { } })); + this._register(this.chatSessionsService.onDidChangeSessionItems((chatSessionType) => { + if (provider.chatSessionType === chatSessionType && this.tree && this.isBodyVisible()) { + this.refreshTreeWithProgress(); + } + })); + if (provider) { // TODO: Why can this be undefined? this.scopedContextKeyService.createKey('chatSessionType', provider.chatSessionType); } @@ -186,12 +193,6 @@ export class SessionsViewPane extends ViewPane { ); } - public refreshTree(): void { - if (this.tree && this.isBodyVisible()) { - this.refreshTreeWithProgress(); - } - } - private isEmpty() { // Check if the tree has the provider node and get its children count if (!this.tree?.hasNode(this.provider)) {