Add event emitters for workspace folder and worktree changes#312288
Merged
DonJayamanne merged 6 commits intomainfrom Apr 24, 2026
Merged
Add event emitters for workspace folder and worktree changes#312288DonJayamanne merged 6 commits intomainfrom
DonJayamanne merged 6 commits intomainfrom
Conversation
… cache management Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
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
cachedChangeslayer 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
cachedChangeslayer can return stale diffs after an invalidation.refreshSession()callstoChatSessionItem()withoutincludeChanges, andtoChatSessionItem()will keep usingthis.cachedChanges.get(session.id)even whenhasCachedChanges()is false (i.e. the underlying caches were cleared). When handlingonDidChangeWorkspaceFolderChanges/onDidChangeWorktreeChanges, consider clearingcachedChangesfor thatsessionId(or adjustingtoChatSessionItemto ignorecachedChangeswhen 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
…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>
mjbvz
approved these changes
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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