Skip to content

Commit 131ccd9

Browse files
bors[bot]Veetaha
andauthored
Merge #4580
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>
2 parents 21132a7 + d605ec9 commit 131ccd9

File tree

14 files changed

+130
-71
lines changed

14 files changed

+130
-71
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_proc_macro_srv/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ cargo_metadata = "0.10.0"
2222
difference = "2.0.0"
2323
# used as proc macro test target
2424
serde_derive = "1.0.106"
25+
ra_toolchain = { path = "../ra_toolchain" }

crates/ra_proc_macro_srv/src/tests/utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::dylib;
44
use crate::ProcMacroSrv;
5-
pub use difference::Changeset as __Changeset;
65
use ra_proc_macro::ListMacrosTask;
76
use std::str::FromStr;
87
use test_utils::assert_eq_text;
@@ -13,7 +12,7 @@ mod fixtures {
1312

1413
// Use current project metadata to get the proc-macro dylib path
1514
pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
16-
let command = Command::new("cargo")
15+
let command = Command::new(ra_toolchain::cargo())
1716
.args(&["check", "--message-format", "json"])
1817
.output()
1918
.unwrap()

crates/rust-analyzer/src/lsp_ext.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,21 @@ pub struct RunnablesParams {
121121
pub position: Option<Position>,
122122
}
123123

124+
// Must strictly correspond to the executable name
125+
#[derive(Serialize, Deserialize, Debug)]
126+
#[serde(rename_all = "lowercase")]
127+
pub enum RunnableKind {
128+
Cargo,
129+
Rustc,
130+
Rustup,
131+
}
132+
124133
#[derive(Deserialize, Serialize, Debug)]
125134
#[serde(rename_all = "camelCase")]
126135
pub struct Runnable {
127136
pub range: Range,
128137
pub label: String,
129-
pub bin: String,
138+
pub kind: RunnableKind,
130139
pub args: Vec<String>,
131140
pub extra_args: Vec<String>,
132141
pub env: FxHashMap<String, String>,

crates/rust-analyzer/src/main_loop/handlers.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ pub fn handle_runnables(
426426
res.push(lsp_ext::Runnable {
427427
range: Default::default(),
428428
label: format!("cargo {} -p {}", cmd, spec.package),
429-
bin: "cargo".to_string(),
429+
kind: lsp_ext::RunnableKind::Cargo,
430430
args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()],
431431
extra_args: Vec::new(),
432432
env: FxHashMap::default(),
@@ -438,7 +438,7 @@ pub fn handle_runnables(
438438
res.push(lsp_ext::Runnable {
439439
range: Default::default(),
440440
label: "cargo check --workspace".to_string(),
441-
bin: "cargo".to_string(),
441+
kind: lsp_ext::RunnableKind::Cargo,
442442
args: vec!["check".to_string(), "--workspace".to_string()],
443443
extra_args: Vec::new(),
444444
env: FxHashMap::default(),
@@ -982,10 +982,11 @@ fn to_lsp_runnable(
982982
target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t))
983983
}
984984
};
985+
985986
Ok(lsp_ext::Runnable {
986987
range: to_proto::range(&line_index, runnable.range),
987988
label,
988-
bin: "cargo".to_string(),
989+
kind: lsp_ext::RunnableKind::Cargo,
989990
args,
990991
extra_args,
991992
env: {

crates/rust-analyzer/tests/heavy_tests/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn foo() {
7979
{
8080
"args": [ "test" ],
8181
"extraArgs": [ "foo", "--nocapture" ],
82-
"bin": "cargo",
82+
"kind": "cargo",
8383
"env": { "RUST_BACKTRACE": "short" },
8484
"cwd": null,
8585
"label": "test foo",
@@ -91,7 +91,7 @@ fn foo() {
9191
{
9292
"args": ["check", "--workspace"],
9393
"extraArgs": [],
94-
"bin": "cargo",
94+
"kind": "cargo",
9595
"env": {},
9696
"cwd": null,
9797
"label": "cargo check --workspace",
@@ -141,7 +141,7 @@ fn main() {}
141141
{
142142
"args": [ "test", "--package", "foo", "--test", "spam" ],
143143
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
144-
"bin": "cargo",
144+
"kind": "cargo",
145145
"env": { "RUST_BACKTRACE": "short" },
146146
"label": "test test_eggs",
147147
"range": {
@@ -153,7 +153,7 @@ fn main() {}
153153
{
154154
"args": [ "check", "--package", "foo" ],
155155
"extraArgs": [],
156-
"bin": "cargo",
156+
"kind": "cargo",
157157
"env": {},
158158
"label": "cargo check -p foo",
159159
"range": {
@@ -165,7 +165,7 @@ fn main() {}
165165
{
166166
"args": [ "test", "--package", "foo" ],
167167
"extraArgs": [],
168-
"bin": "cargo",
168+
"kind": "cargo",
169169
"env": {},
170170
"label": "cargo test -p foo",
171171
"range": {

docs/dev/lsp-extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ interface Runnable {
427427
/// The label to show in the UI.
428428
label: string;
429429
/// The following fields describe a process to spawn.
430-
bin: string;
430+
kind: "cargo" | "rustc" | "rustup";
431431
args: string[];
432432
/// Args for cargo after `--`.
433433
extraArgs: string[];

editors/code/src/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as vscode from 'vscode';
33
import * as path from 'path';
44
import * as ra from './lsp_ext';
55

6-
import { Cargo } from './cargo';
6+
import { Cargo } from './toolchain';
77
import { Ctx } from "./ctx";
88

99
const debugOutput = vscode.window.createOutputChannel("Debug");

editors/code/src/lsp_ext.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ export interface RunnablesParams {
4545
textDocument: lc.TextDocumentIdentifier;
4646
position: lc.Position | null;
4747
}
48+
49+
export type RunnableKind = "cargo" | "rustc" | "rustup";
50+
4851
export interface Runnable {
4952
range: lc.Range;
5053
label: string;
51-
bin: string;
54+
kind: RunnableKind;
5255
args: string[];
5356
extraArgs: string[];
5457
env: { [key: string]: string };

editors/code/src/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode';
22
import * as lc from 'vscode-languageclient';
33
import * as ra from './lsp_ext';
4+
import * as toolchain from "./toolchain";
45

56
import { Ctx, Cmd } from './ctx';
67
import { startDebugSession, getDebugConfiguration } from './debug';
@@ -175,7 +176,7 @@ export function createTask(spec: ra.Runnable): vscode.Task {
175176
const definition: CargoTaskDefinition = {
176177
type: 'cargo',
177178
label: spec.label,
178-
command: spec.bin,
179+
command: toolchain.getPathForExecutable(spec.kind),
179180
args: spec.extraArgs ? [...spec.args, '--', ...spec.extraArgs] : spec.args,
180181
env: Object.assign({}, process.env, spec.env),
181182
};

0 commit comments

Comments
 (0)