Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit 79968e6

Browse files
committed
Remove caching machinery
It didn't hit filesystem anyway so there's no I/O access penalty to be amortized; in most common cases we'll have not more that 5ish top-level workspace folders so the amount of work should be fairly minimal.
1 parent 3bcdb62 commit 79968e6

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function whenChangingWorkspaceFolders(e: WorkspaceFoldersChangeEvent) {
112112
// If a VSCode workspace has been added, check to see if it is part of an existing one, and
113113
// if not, and it is a Rust project (i.e., has a Cargo.toml), then create a new client.
114114
for (let folder of e.added) {
115-
folder = getOuterMostWorkspaceFolder(folder, { cached: false });
115+
folder = getOuterMostWorkspaceFolder(folder);
116116
if (workspaces.has(folder.uri.toString())) {
117117
continue;
118118
}

src/utils/workspace.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,16 @@ export function nearestParentWorkspace(
4545
return curWorkspace;
4646
}
4747

48-
// This is an intermediate, lazy cache used by `getOuterMostWorkspaceFolder`
49-
// and should be regenerated when VSCode workspaces change.
50-
let _cachedSortedWorkspaceFolders: string[] | undefined;
51-
5248
export function getOuterMostWorkspaceFolder(
5349
folder: WorkspaceFolder,
54-
options?: { cached: boolean },
5550
): WorkspaceFolder {
56-
const recalculate = !options || !options.cached;
57-
// Sort workspace folders or used already cached result, if possible
58-
const sortedFolders =
59-
!recalculate && _cachedSortedWorkspaceFolders
60-
? _cachedSortedWorkspaceFolders
61-
: (workspace.workspaceFolders || [])
62-
.map(folder => normalizeUriToPathPrefix(folder.uri))
63-
.sort((a, b) => a.length - b.length);
64-
_cachedSortedWorkspaceFolders = sortedFolders;
51+
const sortedFoldersByPrefix = (workspace.workspaceFolders || [])
52+
.map(folder => normalizeUriToPathPrefix(folder.uri))
53+
.sort((a, b) => a.length - b.length);
6554

6655
const uri = normalizeUriToPathPrefix(folder.uri);
6756

68-
const outermostPath = sortedFolders.find(prefix => uri.startsWith(prefix));
57+
const outermostPath = sortedFoldersByPrefix.find(pre => uri.startsWith(pre));
6958
return outermostPath
7059
? workspace.getWorkspaceFolder(Uri.parse(outermostPath)) || folder
7160
: folder;

0 commit comments

Comments
 (0)