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

Commit c1f1355

Browse files
authored
Merge pull request #555 from Xanewok/wsl-path
Decode URL under WSL on Windows
2 parents 3dd4738 + 6a4a4bd commit c1f1355

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

src/extension.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,11 @@ class ClientWorkspace {
254254
console.log(`code2Protocol for path ${uri.fsPath} -> ${res}`);
255255
return res;
256256
},
257-
protocol2Code: (wslPath: string) => {
258-
if (wslPath.startsWith('file://')) {
259-
wslPath = wslPath.substr('file://'.length);
260-
}
261-
262-
const res = Uri.file(uriWslToWindows(wslPath));
263-
console.log(`protocol2Code for path ${wslPath} -> ${res.fsPath}`);
264-
return res;
257+
protocol2Code: (wslUri: string) => {
258+
const urlDecodedPath = Uri.parse(wslUri).path;
259+
const winPath = Uri.file(uriWslToWindows(urlDecodedPath));
260+
console.log(`protocol2Code for path ${wslUri} -> ${winPath.fsPath}`);
261+
return winPath;
265262
},
266263
};
267264
}

src/rustup.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,14 @@ async function hasToolchain(config: RustupConfig): Promise<boolean> {
9090
return stdout.includes(config.channel);
9191
} catch (e) {
9292
console.log(e);
93-
// rustup not present
93+
const rustupFoundButNotInWSLMode =
94+
config.useWSL && (await hasRustup({ useWSL: false, ...config }));
95+
9496
window.showErrorMessage(
95-
'Rustup not available. Install from https://www.rustup.rs/',
97+
rustupFoundButNotInWSLMode
98+
? `Rustup is installed but can't be found under WSL. Ensure that
99+
invoking \`wsl rustup\` works correctly.`
100+
: 'Rustup not available. Install from https://www.rustup.rs/',
96101
);
97102
throw e;
98103
}
@@ -144,6 +149,7 @@ async function hasRlsComponents(config: RustupConfig): Promise<boolean> {
144149
} catch (e) {
145150
console.log(e);
146151
window.showErrorMessage(`Can't detect RLS components: ${e.message}`);
152+
stopSpinner("Can't detect RLS components");
147153
throw e;
148154
}
149155
}
@@ -218,14 +224,11 @@ export function parseActiveToolchain(rustupOutput: string): string {
218224
throw new Error(`couldn't find active toolchains`);
219225
}
220226

221-
export async function getVersion(
222-
cwd: string,
223-
config: RustupConfig,
224-
): Promise<string> {
227+
export async function getVersion(config: RustupConfig): Promise<string> {
225228
const versionRegex = /rustup ([0-9]+\.[0-9]+\.[0-9]+)/;
226229
const execFile = withWsl(config.useWSL).execFile;
227230

228-
const output = await execFile(config.path, ['--version'], { cwd });
231+
const output = await execFile(config.path, ['--version']);
229232
const versionMatch = output.stdout.toString().match(versionRegex);
230233
if (versionMatch && versionMatch.length >= 2) {
231234
return versionMatch[1];
@@ -234,6 +237,15 @@ export async function getVersion(
234237
}
235238
}
236239

240+
/**
241+
* Returns whether Rustup is invokable and available.
242+
*/
243+
export function hasRustup(config: RustupConfig): Promise<boolean> {
244+
return getVersion(config)
245+
.then(() => true)
246+
.catch(() => false);
247+
}
248+
237249
/**
238250
* Returns active (including local overrides) toolchain, as specified by rustup.
239251
* May throw if rustup at specified path can't be executed.

src/test/rustup.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const config: rustup.RustupConfig = {
1616

1717
suite('Rustup Tests', () => {
1818
test('getVersion', async () => {
19-
const version = await rustup.getVersion('.', config);
19+
const version = await rustup.getVersion(config);
2020
assert(rustupVersion.includes(`rustup ${version}`));
2121
});
2222
test('getActiveChannel', async () => {

0 commit comments

Comments
 (0)