Skip to content

Commit 69b140e

Browse files
committed
Filter out non-existent workspace folders when initializing and updating workspace roots
1 parent ba7503f commit 69b140e

2 files changed

Lines changed: 29 additions & 11 deletions

File tree

apps/editor/src/context/providers/open-editors/open-editors-provider.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ export class OpenEditorsProvider
4242
workspace_folders: readonly vscode.WorkspaceFolder[]
4343
workspace_provider: WorkspaceProvider
4444
}) {
45-
this._workspace_roots = params.workspace_folders.map(
46-
(folder) => folder.uri.fsPath
47-
)
45+
this._workspace_roots = params.workspace_folders
46+
.map((folder) => folder.uri.fsPath)
47+
.filter((folder_path) => fs.existsSync(folder_path))
48+
4849
this._shared_state = SharedFileState.get_instance()
4950
this._workspace_provider = params.workspace_provider
5051

@@ -81,7 +82,9 @@ export class OpenEditorsProvider
8182
public update_workspace_folders(
8283
workspace_folders: readonly vscode.WorkspaceFolder[]
8384
) {
84-
this._workspace_roots = workspace_folders.map((folder) => folder.uri.fsPath)
85+
this._workspace_roots = workspace_folders
86+
.map((folder) => folder.uri.fsPath)
87+
.filter((folder_path) => fs.existsSync(folder_path))
8588
this.refresh()
8689
}
8790

apps/editor/src/context/providers/workspace/workspace-provider.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ export class WorkspaceProvider
9696
context: vscode.ExtensionContext
9797
}) {
9898
this._context = params.context
99-
this._workspace_roots = params.workspace_folders.map(
100-
(folder) => folder.uri.fsPath
101-
)
102-
this._workspace_names = params.workspace_folders.map(
103-
(folder) => folder.name
99+
const valid_folders = params.workspace_folders.filter((folder) =>
100+
fs.existsSync(folder.uri.fsPath)
104101
)
102+
103+
this._workspace_roots = valid_folders.map((folder) => folder.uri.fsPath)
104+
this._workspace_names = valid_folders.map((folder) => folder.name)
105+
105106
this.onDidChangeCheckedFiles(() => this._save_checked_files_state())
106107
this._token_calculator = new TokenCalculator(this, this._context)
107108
this._load_ignore_patterns()
@@ -675,6 +676,9 @@ export class WorkspaceProvider
675676

676677
if (this._workspace_roots.length == 1) {
677678
const single_root = this._workspace_roots[0]
679+
if (!fs.existsSync(single_root)) {
680+
return []
681+
}
678682
const items =
679683
await this._token_calculator.with_token_counting_notification(() =>
680684
this._get_files_and_directories(single_root)
@@ -712,6 +716,9 @@ export class WorkspaceProvider
712716
}
713717

714718
if (this._workspace_roots.length == 1) {
719+
if (!fs.existsSync(this._workspace_roots[0])) {
720+
return []
721+
}
715722
return this._get_files_and_directories(this._workspace_roots[0], true)
716723
} else {
717724
return this._get_workspace_folder_items(true)
@@ -725,6 +732,10 @@ export class WorkspaceProvider
725732
for (let i = 0; i < this._workspace_roots.length; i++) {
726733
const root = this._workspace_roots[i]
727734

735+
if (!fs.existsSync(root)) {
736+
continue
737+
}
738+
728739
if (context_view) {
729740
const state = this._checked_items.get(root)
730741
const is_partially_checked = this._partially_checked_dirs.has(root)
@@ -1620,8 +1631,12 @@ export class WorkspaceProvider
16201631
): Promise<void> {
16211632
const checked_paths = this.get_all_checked_paths()
16221633

1623-
this._workspace_roots = workspace_folders.map((folder) => folder.uri.fsPath)
1624-
this._workspace_names = workspace_folders.map((folder) => folder.name)
1634+
const valid_folders = workspace_folders.filter((folder) =>
1635+
fs.existsSync(folder.uri.fsPath)
1636+
)
1637+
1638+
this._workspace_roots = valid_folders.map((folder) => folder.uri.fsPath)
1639+
this._workspace_names = valid_folders.map((folder) => folder.name)
16251640

16261641
// Clear caches that depend on workspace structure
16271642
this._file_workspace_map.clear()

0 commit comments

Comments
 (0)