Skip to content

Add event emitters for workspace folder and worktree changes#312288

Merged
DonJayamanne merged 6 commits intomainfrom
don/central-goldfish
Apr 24, 2026
Merged

Add event emitters for workspace folder and worktree changes#312288
DonJayamanne merged 6 commits intomainfrom
don/central-goldfish

Conversation

@DonJayamanne
Copy link
Copy Markdown
Contributor

@DonJayamanne DonJayamanne commented Apr 24, 2026

Introduce event emitters to notify changes in workspace folders and worktrees, enhancing cache management for affected sessions. This update improves responsiveness to changes in the workspace environment.

For #309466

… cache management

Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 24, 2026 02:59
@DonJayamanne DonJayamanne self-assigned this Apr 24, 2026
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 adds change-notification plumbing around session diff/changes caching so the Copilot chat sessions UI can respond when workspace folders/worktrees change and when git state changes invalidate cached diffs.

Changes:

  • Introduces per-session events for invalidation of workspace-folder/worktree change caches.
  • Refactors repository-state handling into clearChangesCacheForAffectedSessions(...) and calls it on repo state changes and request completion.
  • Adds an additional in-provider cachedChanges layer to avoid “diff info flashing” during refresh/resolve cycles.
Show a summary per file
File Description
extensions/copilot/src/extension/chatSessions/vscode-node/sessionRequestLifecycle.ts Clears changes cache for other sessions in the same folder after request completion.
extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts Adds local cachedChanges layer and invokes cache clearing after request completion.
extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessions.ts Adds local cachedChanges layer and wires new invalidation events to refresh items in controller path.
extensions/copilot/src/extension/chatSessions/vscode-node/chatSessions.ts Stops passing an item provider into ChatSessionRepositoryTracker in controller path.
extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorktreeServiceImpl.ts Emits a new event when worktree changes cache is cleared.
extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionWorkspaceFolderServiceImpl.ts Emits a new event when workspace-folder changes cache is invalidated.
extensions/copilot/src/extension/chatSessions/vscode-node/chatSessionRepositoryTracker.ts Extracts shared invalidation/refresh logic into clearChangesCacheForAffectedSessions(...).
extensions/copilot/src/extension/chatSessions/common/chatSessionWorktreeService.ts Adds onDidChangeWorktreeChanges to the service interface.
extensions/copilot/src/extension/chatSessions/common/chatSessionWorkspaceFolderService.ts Adds onDidChangeWorkspaceFolderChanges to the service interface.

Copilot's findings

Comments suppressed due to low confidence (1)

extensions/copilot/src/extension/chatSessions/vscode-node/copilotCLIChatSessions.ts:216

  • The new cachedChanges layer can return stale diffs after an invalidation. refreshSession() calls toChatSessionItem() without includeChanges, and toChatSessionItem() will keep using this.cachedChanges.get(session.id) even when hasCachedChanges() is false (i.e. the underlying caches were cleared). When handling onDidChangeWorkspaceFolderChanges/onDidChangeWorktreeChanges, consider clearing cachedChanges for that sessionId (or adjusting toChatSessionItem to ignore cachedChanges when underlying caches were invalidated).
		this._register(this._workspaceFolderService.onDidChangeWorkspaceFolderChanges(e => {
			this.refreshSession({ reason: 'update', sessionId: e.sessionId });
		}));
		this._register(chatSessionWorktreeService.onDidChangeWorktreeChanges(e => {
			this.refreshSession({ reason: 'update', sessionId: e.sessionId });
		}));
  • Files reviewed: 9/9 changed files
  • Comments generated: 5

DonJayamanne and others added 5 commits April 24, 2026 13:08
…onWorktreeService.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…lotCLIChatSessions.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…efreshed sessions to improve UX

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@DonJayamanne DonJayamanne marked this pull request as ready for review April 24, 2026 03:30
@DonJayamanne DonJayamanne enabled auto-merge (squash) April 24, 2026 03:30
@DonJayamanne DonJayamanne merged commit f5d02ff into main Apr 24, 2026
26 checks passed
@DonJayamanne DonJayamanne deleted the don/central-goldfish branch April 24, 2026 03:50
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants