Fix invoking cargo without consulting CARGO or standard installation paths

This commit is contained in:
veetaha 2020-05-23 04:58:22 +03:00
parent 5f7225446e
commit 030d78345f
5 changed files with 16 additions and 5 deletions

View file

@ -126,8 +126,8 @@ export class Cargo {
}
}
// Mirrors `ra_env::get_path_for_executable` implementation
function getCargoPathOrFail(): string {
// Mirrors `ra_toolchain::cargo()` implementation
export function getCargoPathOrFail(): string {
const envVar = process.env.CARGO;
const executableName = "cargo";

View file

@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import { getCargoPathOrFail } from "./cargo";
// This ends up as the `type` key in tasks.json. RLS also uses `cargo` and
// our configuration should be compatible with it so use the same key.
@ -24,6 +25,8 @@ class CargoTaskProvider implements vscode.TaskProvider {
// set of tasks that always exist. These tasks cannot be removed in
// tasks.json - only tweaked.
const cargoPath = getCargoPathOrFail();
return [
{ command: 'build', group: vscode.TaskGroup.Build },
{ command: 'check', group: vscode.TaskGroup.Build },
@ -46,7 +49,7 @@ class CargoTaskProvider implements vscode.TaskProvider {
`cargo ${command}`,
'rust',
// What to do when this command is executed.
new vscode.ShellExecution('cargo', [command]),
new vscode.ShellExecution(cargoPath, [command]),
// Problem matchers.
['$rustc'],
);
@ -80,4 +83,4 @@ class CargoTaskProvider implements vscode.TaskProvider {
export function activateTaskProvider(target: vscode.WorkspaceFolder): vscode.Disposable {
const provider = new CargoTaskProvider(target);
return vscode.tasks.registerTaskProvider(TASK_TYPE, provider);
}
}