4580: Fix invoking cargo without consulting CARGO env var or standard installation paths r=matklad a=Veetaha

Followup for #4329

The pr essentially fixes [this bug](https://youtu.be/EzQ7YIIo1rY?t=2189)

cc @lefticus

Co-authored-by: veetaha <veetaha2@gmail.com>
This commit is contained in:
bors[bot] 2020-06-02 11:58:28 +00:00 committed by GitHub
commit 131ccd9540
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 140 additions and 81 deletions

View file

@ -22,3 +22,4 @@ cargo_metadata = "0.10.0"
difference = "2.0.0"
# used as proc macro test target
serde_derive = "1.0.106"
ra_toolchain = { path = "../ra_toolchain" }

View file

@ -2,7 +2,6 @@
use crate::dylib;
use crate::ProcMacroSrv;
pub use difference::Changeset as __Changeset;
use ra_proc_macro::ListMacrosTask;
use std::str::FromStr;
use test_utils::assert_eq_text;
@ -13,7 +12,7 @@ mod fixtures {
// Use current project metadata to get the proc-macro dylib path
pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
let command = Command::new("cargo")
let command = Command::new(ra_toolchain::cargo())
.args(&["check", "--message-format", "json"])
.output()
.unwrap()

View file

@ -121,12 +121,21 @@ pub struct RunnablesParams {
pub position: Option<Position>,
}
// Must strictly correspond to the executable name
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum RunnableKind {
Cargo,
Rustc,
Rustup,
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Runnable {
pub range: Range,
pub label: String,
pub bin: String,
pub kind: RunnableKind,
pub args: Vec<String>,
pub extra_args: Vec<String>,
pub env: FxHashMap<String, String>,

View file

@ -426,7 +426,7 @@ pub fn handle_runnables(
res.push(lsp_ext::Runnable {
range: Default::default(),
label: format!("cargo {} -p {}", cmd, spec.package),
bin: "cargo".to_string(),
kind: lsp_ext::RunnableKind::Cargo,
args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()],
extra_args: Vec::new(),
env: FxHashMap::default(),
@ -438,7 +438,7 @@ pub fn handle_runnables(
res.push(lsp_ext::Runnable {
range: Default::default(),
label: "cargo check --workspace".to_string(),
bin: "cargo".to_string(),
kind: lsp_ext::RunnableKind::Cargo,
args: vec!["check".to_string(), "--workspace".to_string()],
extra_args: Vec::new(),
env: FxHashMap::default(),
@ -982,10 +982,11 @@ fn to_lsp_runnable(
target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t))
}
};
Ok(lsp_ext::Runnable {
range: to_proto::range(&line_index, runnable.range),
label,
bin: "cargo".to_string(),
kind: lsp_ext::RunnableKind::Cargo,
args,
extra_args,
env: {

View file

@ -79,7 +79,7 @@ fn foo() {
{
"args": [ "test" ],
"extraArgs": [ "foo", "--nocapture" ],
"bin": "cargo",
"kind": "cargo",
"env": { "RUST_BACKTRACE": "short" },
"cwd": null,
"label": "test foo",
@ -91,7 +91,7 @@ fn foo() {
{
"args": ["check", "--workspace"],
"extraArgs": [],
"bin": "cargo",
"kind": "cargo",
"env": {},
"cwd": null,
"label": "cargo check --workspace",
@ -141,7 +141,7 @@ fn main() {}
{
"args": [ "test", "--package", "foo", "--test", "spam" ],
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
"bin": "cargo",
"kind": "cargo",
"env": { "RUST_BACKTRACE": "short" },
"label": "test test_eggs",
"range": {
@ -153,7 +153,7 @@ fn main() {}
{
"args": [ "check", "--package", "foo" ],
"extraArgs": [],
"bin": "cargo",
"kind": "cargo",
"env": {},
"label": "cargo check -p foo",
"range": {
@ -165,7 +165,7 @@ fn main() {}
{
"args": [ "test", "--package", "foo" ],
"extraArgs": [],
"bin": "cargo",
"kind": "cargo",
"env": {},
"label": "cargo test -p foo",
"range": {