Skip to content

fix(plugin): strengthen IDE refresh after worktree symlink switch#42

Merged
guodong-sq merged 1 commit intomainfrom
guodong/fix-symlink-switch-refresh
Mar 21, 2026
Merged

fix(plugin): strengthen IDE refresh after worktree symlink switch#42
guodong-sq merged 1 commit intomainfrom
guodong/fix-symlink-switch-refresh

Conversation

@guodong-sq
Copy link
Copy Markdown
Collaborator

@guodong-sq guodong-sq commented Mar 21, 2026

Summary

  • VFS refresh: Replace shallow single-root refresh with multi-path LocalFileSystem.refreshNioFiles targeting the symlink, its .git child, the new target, and the main repo root — so VFS re-reads the symlink entry and rescans the new target tree
  • Editor/PSI/UI propagation: After document reload, reparse PSI trees, drop PSI caches, fire a synthetic roots-changed event, then refresh Project View, editor notifications, and daemon code analyzer
  • Git state: Re-set VCS directory mappings to trigger git4idea's root re-detection pipeline before repo.update(), so the .git file's new gitdir: pointer is re-read

Fixes three symptoms after worktree switching:

  1. Project View sometimes not refreshing until manual "Reload from Disk"
  2. Open editors sometimes showing stale content until tab-switching
  3. Git integration (blame, GitHub navigation) breaking after repeated switches

Test plan

  • Switch between two worktrees with different file sets — Project View updates immediately
  • Keep a file open across switch — content updates without tab-switching
  • Run "Annotate with Git Blame" after switch — annotations are correct
  • "Open on GitHub" after switch — URL points to correct branch
  • Status bar branch display matches target worktree
  • Switch back and forth 10+ times — all above still work
  • Three-way switch A→B→C→A — correct state at each step

🤖 Generated with Claude Code

After atomically swapping the active worktree symlink, the IDE's VFS,
editor, PSI, and git state could become stale because the project path
string doesn't change — only the symlink target does.

Phase 3 (VFS): Replace single-root VfsUtil.findFileByIoFile with
LocalFileSystem.refreshNioFiles on all relevant paths (symlink, target,
.git, main repo root) so VFS re-reads the symlink entry and rescans the
new target tree. Explicitly refresh .git child for gitdir pointer.

Phase 4 (Editor/PSI/UI): After document reload, reparse PSI trees,
commit documents, drop PSI caches, fire a synthetic roots-changed event
via ProjectRootManagerEx.makeRootsChange, then refresh Project View,
editor notifications, and daemon code analyzer.

Phase 5 (Git): Re-set VCS directory mappings to trigger git4idea's root
re-detection pipeline before calling repo.update(), so the new .git
gitdir pointer is re-read. Mark project root dirty in addition to
markEverythingDirty for gutter indicator updates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@guodong-sq guodong-sq merged commit c3381c2 into main Mar 21, 2026
5 checks passed
@guodong-sq guodong-sq deleted the guodong/fix-symlink-switch-refresh branch March 24, 2026 04:21
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.

1 participant