Skip to content

Commit 8874a60

Browse files
authored
Merge pull request microsoft#241742 from mjbvz/upper-walrus
Always try sending along project root paths
2 parents cddfc78 + 9697d7e commit 8874a60

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

extensions/typescript-language-features/src/tsServer/bufferSyncSupport.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,20 @@ class SyncedBuffer {
191191
}
192192

193193
private getProjectRootPath(resource: vscode.Uri): string | undefined {
194-
const workspaceRoot = this.client.getWorkspaceRootForResource(resource);
194+
let workspaceRoot = this.client.getWorkspaceRootForResource(resource);
195+
196+
// If we didn't find a real workspace, we still want to try sending along a workspace folder
197+
// to prevent TS from loading projects from outside of any workspace.
198+
// Just pick the highest level one on the same FS even though the file is outside of it
199+
if (!workspaceRoot && vscode.workspace.workspaceFolders) {
200+
for (const root of Array.from(vscode.workspace.workspaceFolders).sort((a, b) => a.uri.path.length - b.uri.path.length)) {
201+
if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
202+
workspaceRoot = root.uri;
203+
break;
204+
}
205+
}
206+
}
207+
195208
if (workspaceRoot) {
196209
const tsRoot = this.client.toTsFilePath(workspaceRoot);
197210
return tsRoot?.startsWith(inMemoryResourcePrefix) ? undefined : tsRoot;

extensions/typescript-language-features/src/typescriptServiceClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,10 @@ export default class TypeScriptServiceClient extends Disposable implements IType
836836
}
837837
}
838838

839-
for (const root of roots.sort((a, b) => a.uri.fsPath.length - b.uri.fsPath.length)) {
839+
// Find the highest level workspace folder that contains the file
840+
for (const root of roots.sort((a, b) => a.uri.path.length - b.uri.path.length)) {
840841
if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
841-
if (resource.fsPath.startsWith(root.uri.fsPath + path.sep)) {
842+
if (resource.path.startsWith(root.uri.path + '/')) {
842843
return root.uri;
843844
}
844845
}

0 commit comments

Comments
 (0)