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

Fix workspace path when multiProjectSetup is enabled #759

Merged
merged 12 commits into from
Apr 17, 2020
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
"rust-client.enableMultiProjectSetup": {
"type": "boolean",
"default": false,
"description": "Allow multiple projects in the same folder, along with remove the constraint that the cargo.toml must be located at the root. (Experimental: might not work for certain setups)"
"description": "Allow multiple projects in the same folder, along with removing the constraint that the cargo.toml must be located at the root. (Experimental: might not work for certain setups)"
},
"rust.sysroot": {
"type": [
Expand Down
10 changes: 9 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,16 @@ class ClientWorkspace {
return this.makeRlsProcess();
};

// Something else is put front of files when pattern matching that prevents the windows version from picking up the files
// This should be safe as the uri is a absolute path that includes the drive + colon
// i.e. a pattern would become "**/c:/some/path**" and since colon is reserved only the root can ever contain it.
const isWin = process.platform === 'win32';
const windowsHack = isWin ? '**' : '';

const pattern = this.config.multiProjectEnabled
? `${this.folder.uri.path}/**`
? `${windowsHack}${this.folder.uri.path}/**`
: undefined;

const collectionName = this.config.multiProjectEnabled
? `rust ${this.folder.uri.toString()}`
: 'rust';
Expand Down Expand Up @@ -309,6 +316,7 @@ class ClientWorkspace {
const ws =
multiProjectEnabled && activeWorkspace ? activeWorkspace : this;
await ws.stop();
commandsRegistered = true;
return ws.start(context);
});
this.disposables.push(restartServer);
Expand Down
6 changes: 5 additions & 1 deletion src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ function detectCargoTasks(target: WorkspaceFolder): Task[] {
.map(({ subcommand, group }) => ({
definition: { subcommand, type: TASK_TYPE },
label: `cargo ${subcommand}`,
execution: createShellExecution({ command: 'cargo', args: [subcommand] }),
execution: createShellExecution({
command: 'cargo',
args: [subcommand],
cwd: target.uri.fsPath,
}),
group,
problemMatchers: ['$rustc'],
}))
Expand Down
12 changes: 8 additions & 4 deletions src/workspace_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function nearestParentWorkspace(
filePath: string,
): WorkspaceFolder {
// check that the workspace folder already contains the "Cargo.toml"
const workspaceRoot = path.parse(curWorkspace.uri.fsPath).dir;
const workspaceRoot = curWorkspace.uri.fsPath;
const rootManifest = path.join(workspaceRoot, 'Cargo.toml');
if (fs.existsSync(rootManifest)) {
return curWorkspace;
Expand All @@ -25,16 +25,20 @@ export function nearestParentWorkspace(
break;
}

// break in case the strip folder has not changed
if (workspaceRoot === path.parse(current).dir) {
// break in case the strip folder reached the workspace root
if (workspaceRoot === current) {
break;
}

// check if "Cargo.toml" is present in the parent folder
const cargoPath = path.join(current, 'Cargo.toml');
if (fs.existsSync(cargoPath)) {
// ghetto change the uri on Workspace folder to make vscode think it's located elsewhere
return { ...curWorkspace, uri: Uri.parse(current) };
return {
...curWorkspace,
name: path.basename(current),
uri: Uri.file(current),
};
}
}

Expand Down