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

1
Cargo.lock generated
View file

@ -1364,6 +1364,7 @@ dependencies = [
"ra_syntax",
"ra_text_edit",
"ra_tt",
"ra_toolchain",
"ra_vfs",
"rand",
"relative-path",

View file

@ -48,6 +48,7 @@ hir = { path = "../ra_hir", package = "ra_hir" }
hir_def = { path = "../ra_hir_def", package = "ra_hir_def" }
hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" }
ra_proc_macro_srv = { path = "../ra_proc_macro_srv" }
ra_toolchain = { path = "../ra_toolchain" }
[target.'cfg(windows)'.dependencies]
winapi = "0.3.8"

View file

@ -40,6 +40,7 @@ use crate::{
world::WorldSnapshot,
LspError, Result,
};
use anyhow::Context;
pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
let _p = profile("handle_analyzer_status");
@ -982,10 +983,15 @@ fn to_lsp_runnable(
target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t))
}
};
let cargo_path = ra_toolchain::cargo()
.to_str()
.context("Path to cargo executable contains invalid UTF8 characters")?
.to_owned();
Ok(lsp_ext::Runnable {
range: to_proto::range(&line_index, runnable.range),
label,
bin: "cargo".to_string(),
bin: cargo_path,
args,
extra_args,
env: {

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'],
);