Skip to content

fix chatSession swapping when in sidebar chat#281312

Merged
joshspicer merged 1 commit intomainfrom
joshspicer/fix-swap
Dec 4, 2025
Merged

fix chatSession swapping when in sidebar chat#281312
joshspicer merged 1 commit intomainfrom
joshspicer/fix-swap

Conversation

@joshspicer
Copy link
Copy Markdown
Member

fix #281270

Copilot AI review requested due to automatic review settings December 4, 2025 18:40
@joshspicer joshspicer enabled auto-merge (squash) December 4, 2025 18:40
@vs-code-engineering vs-code-engineering Bot added this to the November 2025 milestone Dec 4, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where chat sessions were not properly swapping when opened in the sidebar chat view. The fix adds logic to handle the case when a chat session exists as a widget in the sidebar (as opposed to being open in an editor).

Key changes:

  • Added IChatWidgetService dependency injection to handle sidebar chat widgets
  • Imported necessary types (ChatViewPaneTarget, isIChatViewViewContext) for working with chat view contexts
  • Added fallback logic to handle session swapping in sidebar chat views after the existing editor handling

const chatViewWidget = this._chatWidgetService.getWidgetBySessionResource(originalResource);
if (chatViewWidget && isIChatViewViewContext(chatViewWidget.viewContext)) {
await this._chatSessionsService.getOrCreateChatSession(modifiedResource, CancellationToken.None);
await this._chatWidgetService.openSession(modifiedResource, ChatViewPaneTarget, { preserveFocus: true });
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix correctly handles chat session swapping in the sidebar, but there's a potential issue: if getWidgetBySessionResource returns a widget but isIChatViewViewContext returns false (e.g., for a quick chat or inline chat), the function will silently do nothing instead of handling that case or logging it. Consider adding an else clause to handle non-view contexts or at least log when a widget exists but isn't in the expected context.

Suggested change
await this._chatWidgetService.openSession(modifiedResource, ChatViewPaneTarget, { preserveFocus: true });
await this._chatWidgetService.openSession(modifiedResource, ChatViewPaneTarget, { preserveFocus: true });
} else if (chatViewWidget) {
this._logService.trace(`$onDidCommitChatSessionItem: widget found for resource ${originalResource} but not in view context (context: ${chatViewWidget.viewContext}) - no action taken`);

Copilot uses AI. Check for mistakes.
Comment on lines +440 to 444
const chatViewWidget = this._chatWidgetService.getWidgetBySessionResource(originalResource);
if (chatViewWidget && isIChatViewViewContext(chatViewWidget.viewContext)) {
await this._chatSessionsService.getOrCreateChatSession(modifiedResource, CancellationToken.None);
await this._chatWidgetService.openSession(modifiedResource, ChatViewPaneTarget, { preserveFocus: true });
}
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new code path for handling sidebar chat session swapping lacks test coverage. Consider adding a test case in mainThreadChatSessions.test.ts that verifies the behavior when a chat view widget exists and $onDidCommitChatSessionItem is called, ensuring the session is properly opened in the sidebar.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 4, 2025

@joshspicer I've opened a new pull request, #281314, to work on those changes. Once the pull request is ready, I'll request review from you.

@joshspicer joshspicer merged commit 9fd1fe9 into main Dec 4, 2025
33 of 34 checks passed
@joshspicer joshspicer deleted the joshspicer/fix-swap branch December 4, 2025 19:00

const chatViewWidget = this._chatWidgetService.getWidgetBySessionResource(originalResource);
if (chatViewWidget && isIChatViewViewContext(chatViewWidget.viewContext)) {
await this._chatSessionsService.getOrCreateChatSession(modifiedResource, CancellationToken.None);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have to do this step? I believe you should only have to call openSession

@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jan 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

onDidCommitChatSessionItem doesn't work with background chat in view

5 participants