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

Commit c3d5421

Browse files
authored
Merge pull request #759 from jannickj/fix-pathing-for-windows
Fix workspace path when multiProjectSetup is enabled
2 parents 68861a2 + 65480c5 commit c3d5421

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
"rust-client.enableMultiProjectSetup": {
225225
"type": "boolean",
226226
"default": false,
227-
"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)"
227+
"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)"
228228
},
229229
"rust.sysroot": {
230230
"type": [

src/extension.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,16 @@ class ClientWorkspace {
207207
return this.makeRlsProcess();
208208
};
209209

210+
// Something else is put front of files when pattern matching that prevents the windows version from picking up the files
211+
// This should be safe as the uri is a absolute path that includes the drive + colon
212+
// i.e. a pattern would become "**/c:/some/path**" and since colon is reserved only the root can ever contain it.
213+
const isWin = process.platform === 'win32';
214+
const windowsHack = isWin ? '**' : '';
215+
210216
const pattern = this.config.multiProjectEnabled
211-
? `${this.folder.uri.path}/**`
217+
? `${windowsHack}${this.folder.uri.path}/**`
212218
: undefined;
219+
213220
const collectionName = this.config.multiProjectEnabled
214221
? `rust ${this.folder.uri.toString()}`
215222
: 'rust';
@@ -309,6 +316,7 @@ class ClientWorkspace {
309316
const ws =
310317
multiProjectEnabled && activeWorkspace ? activeWorkspace : this;
311318
await ws.stop();
319+
commandsRegistered = true;
312320
return ws.start(context);
313321
});
314322
this.disposables.push(restartServer);

src/tasks.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ function detectCargoTasks(target: WorkspaceFolder): Task[] {
7878
.map(({ subcommand, group }) => ({
7979
definition: { subcommand, type: TASK_TYPE },
8080
label: `cargo ${subcommand}`,
81-
execution: createShellExecution({ command: 'cargo', args: [subcommand] }),
81+
execution: createShellExecution({
82+
command: 'cargo',
83+
args: [subcommand],
84+
cwd: target.uri.fsPath,
85+
}),
8286
group,
8387
problemMatchers: ['$rustc'],
8488
}))

src/workspace_util.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function nearestParentWorkspace(
88
filePath: string,
99
): WorkspaceFolder {
1010
// check that the workspace folder already contains the "Cargo.toml"
11-
const workspaceRoot = path.parse(curWorkspace.uri.fsPath).dir;
11+
const workspaceRoot = curWorkspace.uri.fsPath;
1212
const rootManifest = path.join(workspaceRoot, 'Cargo.toml');
1313
if (fs.existsSync(rootManifest)) {
1414
return curWorkspace;
@@ -25,16 +25,20 @@ export function nearestParentWorkspace(
2525
break;
2626
}
2727

28-
// break in case the strip folder has not changed
29-
if (workspaceRoot === path.parse(current).dir) {
28+
// break in case the strip folder reached the workspace root
29+
if (workspaceRoot === current) {
3030
break;
3131
}
3232

3333
// check if "Cargo.toml" is present in the parent folder
3434
const cargoPath = path.join(current, 'Cargo.toml');
3535
if (fs.existsSync(cargoPath)) {
3636
// ghetto change the uri on Workspace folder to make vscode think it's located elsewhere
37-
return { ...curWorkspace, uri: Uri.parse(current) };
37+
return {
38+
...curWorkspace,
39+
name: path.basename(current),
40+
uri: Uri.file(current),
41+
};
3842
}
3943
}
4044

0 commit comments

Comments
 (0)