From a9154815302e090e59f956c8448bb165f5bc9fe9 Mon Sep 17 00:00:00 2001 From: winterdrive <90021888+winterdrive@users.noreply.github.com> Date: Sat, 27 Jun 2026 01:30:32 +0800 Subject: [PATCH] fix: set up FileSystemWatchers for scopes added after workspace folder 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 --- src/extension.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/extension.ts b/src/extension.ts index e433cf9..626d994 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -236,12 +236,19 @@ export async function activate(context: vscode.ExtensionContext) { // 為每個 ConfigScope 建立 FileSystemWatcher(多 scope 支援) setupWatchers(provider.configScopes, provider, context); + const watchedScopeIds = new Set(provider.configScopes.map(s => s.id)); // 監聽工作區資料夾動態變更(新增/移除 folder) context.subscriptions.push( vscode.workspace.onDidChangeWorkspaceFolders(() => { // 重新執行 discovery 並更新 provider 的 configScopes provider.reinitializeScopes(); + // 為新增的 scope 建立 FileSystemWatcher(避免重複建立已有的) + 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)); + } }) ); }