mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Merge #4154
4154: Add `cargo test` to the list of Run commands r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
d22d88f0dc
3 changed files with 64 additions and 63 deletions
|
@ -9,6 +9,7 @@ use crate::{world::WorldSnapshot, Result};
|
|||
///
|
||||
/// We use it to cook up the set of cli args we need to pass to Cargo to
|
||||
/// build/test/run the target.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct CargoTargetSpec {
|
||||
pub(crate) package: String,
|
||||
pub(crate) target: String,
|
||||
|
|
|
@ -393,28 +393,37 @@ pub fn handle_runnables(
|
|||
}
|
||||
res.push(to_lsp_runnable(&world, file_id, runnable)?);
|
||||
}
|
||||
let mut check_args = vec!["check".to_string()];
|
||||
let label;
|
||||
// Add `cargo check` and `cargo test` for the whole package
|
||||
match CargoTargetSpec::for_file(&world, file_id)? {
|
||||
Some(spec) => {
|
||||
label = format!("cargo check -p {}", spec.package);
|
||||
spec.push_to(&mut check_args);
|
||||
for &cmd in ["check", "test"].iter() {
|
||||
res.push(req::Runnable {
|
||||
range: Default::default(),
|
||||
label: format!("cargo {} -p {}", cmd, spec.package),
|
||||
bin: "cargo".to_string(),
|
||||
args: {
|
||||
let mut args = vec![cmd.to_string()];
|
||||
spec.clone().push_to(&mut args);
|
||||
args
|
||||
},
|
||||
extra_args: Vec::new(),
|
||||
env: FxHashMap::default(),
|
||||
cwd: workspace_root.map(|root| root.to_owned()),
|
||||
})
|
||||
}
|
||||
}
|
||||
None => {
|
||||
label = "cargo check --all".to_string();
|
||||
check_args.push("--all".to_string())
|
||||
res.push(req::Runnable {
|
||||
range: Default::default(),
|
||||
label: "cargo check --workspace".to_string(),
|
||||
bin: "cargo".to_string(),
|
||||
args: vec!["check".to_string(), "--workspace".to_string()],
|
||||
extra_args: Vec::new(),
|
||||
env: FxHashMap::default(),
|
||||
cwd: workspace_root.map(|root| root.to_owned()),
|
||||
});
|
||||
}
|
||||
}
|
||||
// Always add `cargo check`.
|
||||
res.push(req::Runnable {
|
||||
range: Default::default(),
|
||||
label,
|
||||
bin: "cargo".to_string(),
|
||||
args: check_args,
|
||||
extra_args: Vec::new(),
|
||||
env: FxHashMap::default(),
|
||||
cwd: workspace_root.map(|root| root.to_owned()),
|
||||
});
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
|
|
@ -87,24 +87,15 @@ fn foo() {
|
|||
}
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
"check",
|
||||
"--all"
|
||||
],
|
||||
"args": ["check", "--workspace"],
|
||||
"extraArgs": [],
|
||||
"bin": "cargo",
|
||||
"env": {},
|
||||
"cwd": null,
|
||||
"label": "cargo check --all",
|
||||
"label": "cargo check --workspace",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 0,
|
||||
"line": 0
|
||||
},
|
||||
"start": {
|
||||
"character": 0,
|
||||
"line": 0
|
||||
}
|
||||
"end": { "character": 0, "line": 0 },
|
||||
"start": { "character": 0, "line": 0 }
|
||||
}
|
||||
}
|
||||
]),
|
||||
|
@ -145,42 +136,42 @@ fn main() {}
|
|||
server.request::<Runnables>(
|
||||
RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None },
|
||||
json!([
|
||||
{
|
||||
"args": [ "test", "--package", "foo", "--test", "spam" ],
|
||||
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
|
||||
"bin": "cargo",
|
||||
"env": { "RUST_BACKTRACE": "short" },
|
||||
"label": "test test_eggs",
|
||||
"range": {
|
||||
"end": { "character": 17, "line": 1 },
|
||||
"start": { "character": 0, "line": 0 }
|
||||
},
|
||||
"cwd": server.path().join("foo")
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
"check",
|
||||
"--package",
|
||||
"foo",
|
||||
"--test",
|
||||
"spam"
|
||||
],
|
||||
"extraArgs": [],
|
||||
"bin": "cargo",
|
||||
"env": {},
|
||||
"cwd": server.path().join("foo"),
|
||||
"label": "cargo check -p foo",
|
||||
"range": {
|
||||
"end": {
|
||||
"character": 0,
|
||||
"line": 0
|
||||
{
|
||||
"args": [ "test", "--package", "foo", "--test", "spam" ],
|
||||
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
|
||||
"bin": "cargo",
|
||||
"env": { "RUST_BACKTRACE": "short" },
|
||||
"label": "test test_eggs",
|
||||
"range": {
|
||||
"end": { "character": 17, "line": 1 },
|
||||
"start": { "character": 0, "line": 0 }
|
||||
},
|
||||
"start": {
|
||||
"character": 0,
|
||||
"line": 0
|
||||
}
|
||||
"cwd": server.path().join("foo")
|
||||
},
|
||||
{
|
||||
"args": [ "check", "--package", "foo", "--test", "spam" ],
|
||||
"extraArgs": [],
|
||||
"bin": "cargo",
|
||||
"env": {},
|
||||
"label": "cargo check -p foo",
|
||||
"range": {
|
||||
"end": { "character": 0, "line": 0 },
|
||||
"start": { "character": 0, "line": 0 }
|
||||
},
|
||||
"cwd": server.path().join("foo")
|
||||
},
|
||||
{
|
||||
"args": [ "test", "--package", "foo", "--test", "spam" ],
|
||||
"extraArgs": [],
|
||||
"bin": "cargo",
|
||||
"env": {},
|
||||
"label": "cargo test -p foo",
|
||||
"range": {
|
||||
"end": { "character": 0, "line": 0 },
|
||||
"start": { "character": 0, "line": 0 }
|
||||
},
|
||||
"cwd": server.path().join("foo")
|
||||
}
|
||||
}
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue