fix: persist SCM repository visibility state across restarts#301029
Open
kno wants to merge 77 commits into
Open
fix: persist SCM repository visibility state across restarts#301029kno wants to merge 77 commits into
kno wants to merge 77 commits into
Conversation
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
18fff29 to
1864f58
Compare
Contributor
Author
@microsoft-github-policy-service agree |
SCM repository visibility was not properly restored on restart due to two issues in the onDidAddRepository restoration logic: 1. Repositories with isHidden (e.g., Copilot worktrees) were not in the saved state but triggered the index === -1 path, which made ALL repos visible and reset the didSelectRepository flag. 2. Genuinely new repos (not in previous state) also triggered the same path, making all existing repos visible instead of only adding the new repo. The fix: - Skip the restoration logic for isHidden repos (they are still tracked internally but don't affect visibility restoration) - New repos are added as visible without changing existing repos' visibility state
1864f58 to
a27b3d4
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes SCM repository visibility restoration on startup by preventing hidden SCM providers (e.g. Copilot worktrees) and newly-added repositories from corrupting previously-saved visibility state (scm:view:visibleRepositories).
Changes:
- Updated
SCMViewService.onDidAddRepositoryto skip restoration logic forisHiddenproviders and to treat repos missing frompreviousStateas “new” without resetting existing visibility state. - Added a new test suite covering restoration with hidden providers, new repositories, and different registration orders.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
src/vs/workbench/contrib/scm/browser/scmViewService.ts |
Adjusts repository-add restoration logic to handle isHidden and new repos without breaking persisted visibility. |
src/vs/workbench/contrib/scm/test/browser/scmViewService.test.ts |
Adds tests for visibility persistence scenarios across restarts and registration order variations. |
- Replace `as any` casts with ISCMRepositorySortKey.DiscoveryTime in tests - Fix misleading comment about visibility in single-select mode - Fix bug where new repo registered before known repos loses visibility during state restoration (preserve new repos in the first-visible reset) - Add test for new-repo-before-known-repos registration order - Fix SCMMenus.dispose() to properly clean up titleMenu and menus map - Fix SCMService to dispose inputHistory and emitters - Fix test disposal ordering and Event.debounce subscription init
…w repo registers first - Only include repos from previousState in the removed event (not new repos that remain visible), fixing spurious UI state disposal in SCMViewPane - Clear all repos during the reset block so single-select mode correctly restores the saved selection even when a new repo registered earlier - Re-apply visibility to new repos after the first restored repo is placed, merged into a single event to avoid bouncing add/removed deltas - Add assertion that new repos never appear in removed events during startup Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment on lines
+243
to
+247
| if (e.action && hasKey(e.action, 'keepOpen') && e.action.keepOpen) { | ||
| for (const item of this.viewItems) { | ||
| if (item instanceof BaseMenuActionViewItem) { | ||
| // Re-evaluate the action's state from context keys | ||
| if (hasKey(item.action, 'refreshState')) { |
Comment on lines
+28
to
+33
| /** | ||
| * When true, the context menu will not close when this item is triggered. | ||
| * This is useful for toggle actions in menus where the user may want to | ||
| * change multiple items without having to reopen the menu. | ||
| */ | ||
| keepOpen?: boolean; |
Comment on lines
+657
to
+662
| refreshState(): void { | ||
| (this as unknown as { enabled: boolean }).enabled = !this._precondition || this._contextKeyService.contextMatchesRules(this._precondition); | ||
| (this as unknown as { checked: boolean | undefined }).checked = this._toggledCondition | ||
| ? this._contextKeyService.contextMatchesRules(this._toggledCondition) | ||
| : undefined; | ||
| } |
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.
Summary
Fixes #301028
isHiddenrepos (e.g., Copilot worktrees) no longer corrupt the visibility restoration on startup. They are skipped in thepreviousStatelogic since they were never part of the saved state.didSelectRepositoryflag.Changes
scmViewService.ts: FixedonDidAddRepositoryto properly handleisHiddenrepos and new repos during state restorationscmViewService.test.ts: Added 4 tests covering visibility persistence scenariosTest plan