Skip to content

[Routine - VT] fix: set up FileSystemWatchers for scopes added after workspace folder change#68

Draft
winterdrive wants to merge 1 commit into
mainfrom
routine/vt-fix-watcher-new-scope-260627
Draft

[Routine - VT] fix: set up FileSystemWatchers for scopes added after workspace folder change#68
winterdrive wants to merge 1 commit into
mainfrom
routine/vt-fix-watcher-new-scope-260627

Conversation

@winterdrive

Copy link
Copy Markdown
Owner

Pre-flight Check

Active branches / open PRs checked before this fix:

This PR only modifies src/extension.ts, which is untouched by all active branches — no conflicts.

Changes

File: src/extension.ts

When onDidChangeWorkspaceFolders fires, provider.reinitializeScopes() correctly refreshes provider.configScopes with newly added workspace folders. However, setupWatchers() was only called once at extension activation — new scopes had no FileSystemWatcher monitoring their virtualTab.json. Externally-edited config files in dynamically added folders would not auto-refresh the tree view.

Fix: After reinitializeScopes(), filter provider.configScopes to find scopes that don't yet have a watcher, and call setupWatchers only for those new scopes. A Set<string> (watchedScopeIds) tracks which scope IDs already have watchers to prevent duplicate registrations.

+    const watchedScopeIds = new Set<string>(provider.configScopes.map(s => s.id));

     context.subscriptions.push(
         vscode.workspace.onDidChangeWorkspaceFolders(() => {
             provider.reinitializeScopes();
+            const newScopes = provider.configScopes.filter(s => !watchedScopeIds.has(s.id));
+            if (newScopes.length > 0) {
+                setupWatchers(newScopes, provider, context);
+                newScopes.forEach(s => watchedScopeIds.add(s.id));
+            }
         })
     );

Safety Verification

  • tsc --noEmit: No errors.
  • npm test: 473/473 tests pass. The 1 suite-level failure is a pre-existing TypeScript symbol collision between two git worktrees (busy-yalow-edb734 and trusting-vaughan-0206eb) — unrelated to this change.
  • No package.json commands, configuration keys, or serialization format changed.

🤖 Generated with Claude Code

…r change

When onDidChangeWorkspaceFolders fires and reinitializeScopes() adds new
ConfigScopes, no FileSystemWatcher was created for them. External edits to
virtualTab.json in newly added folders would not auto-refresh the tree view.

Now tracks which scope IDs already have a watcher and only creates new
watchers for previously-unseen scopes, avoiding duplicate registrations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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