Merge pull request #241742 from mjbvz/upper-walrus

Always try sending along project root paths
This commit is contained in:
Matt Bierner
2025-02-26 14:12:12 -08:00
committed by GitHub
2 changed files with 17 additions and 3 deletions

View File

@@ -191,7 +191,20 @@ class SyncedBuffer {
}
private getProjectRootPath(resource: vscode.Uri): string | undefined {
const workspaceRoot = this.client.getWorkspaceRootForResource(resource);
let workspaceRoot = this.client.getWorkspaceRootForResource(resource);
// If we didn't find a real workspace, we still want to try sending along a workspace folder
// to prevent TS from loading projects from outside of any workspace.
// Just pick the highest level one on the same FS even though the file is outside of it
if (!workspaceRoot && vscode.workspace.workspaceFolders) {
for (const root of Array.from(vscode.workspace.workspaceFolders).sort((a, b) => a.uri.path.length - b.uri.path.length)) {
if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
workspaceRoot = root.uri;
break;
}
}
}
if (workspaceRoot) {
const tsRoot = this.client.toTsFilePath(workspaceRoot);
return tsRoot?.startsWith(inMemoryResourcePrefix) ? undefined : tsRoot;

View File

@@ -836,9 +836,10 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}
}
for (const root of roots.sort((a, b) => a.uri.fsPath.length - b.uri.fsPath.length)) {
// Find the highest level workspace folder that contains the file
for (const root of roots.sort((a, b) => a.uri.path.length - b.uri.path.length)) {
if (root.uri.scheme === resource.scheme && root.uri.authority === resource.authority) {
if (resource.fsPath.startsWith(root.uri.fsPath + path.sep)) {
if (resource.path.startsWith(root.uri.path + '/')) {
return root.uri;
}
}