Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always try sending along project root paths #241742

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Loading