Skip to content

Commit 8c802a3

Browse files
bors[bot]urbandove
andauthored
Merge #5513
5513: Try figure out correct workspace in vscode multi root workspace r=vsrs a=urbandove the code to replace the root with the `${workspaceRoot}` arg breaks in multi root workspaces as it needs a qualifier `${workspaceRoot:workspaceName}` This PR attempts to figure out the root workspace - and if it cant find it falls back to the first workspace Co-authored-by: Urban Dove <urbandove80@gmail.com>
2 parents 683d0a4 + a85e647 commit 8c802a3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

editors/code/src/debug.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,17 @@ async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<v
8787
debugOutput.show(true);
8888
}
8989

90-
const wsFolder = path.normalize(vscode.workspace.workspaceFolders![0].uri.fsPath); // folder exists or RA is not active.
90+
const isMultiFolderWorkspace = vscode.workspace.workspaceFolders!.length > 1;
91+
const firstWorkspace = vscode.workspace.workspaceFolders![0]; // folder exists or RA is not active.
92+
const workspace = !isMultiFolderWorkspace || !runnable.args.workspaceRoot ?
93+
firstWorkspace :
94+
vscode.workspace.workspaceFolders!.find(w => runnable.args.workspaceRoot?.includes(w.uri.fsPath)) || firstWorkspace;
95+
96+
const wsFolder = path.normalize(workspace.uri.fsPath);
97+
const workspaceQualifier = isMultiFolderWorkspace ? `:${workspace.name}` : '';
9198
function simplifyPath(p: string): string {
92-
return path.normalize(p).replace(wsFolder, '${workspaceRoot}');
99+
// see https://github.com/rust-analyzer/rust-analyzer/pull/5513#issuecomment-663458818 for why this is needed
100+
return path.normalize(p).replace(wsFolder, '${workspaceFolder' + workspaceQualifier + '}');
93101
}
94102

95103
const executable = await getDebugExecutable(runnable);

0 commit comments

Comments
 (0)