mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +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
|
/// We use it to cook up the set of cli args we need to pass to Cargo to
|
||||||
/// build/test/run the target.
|
/// build/test/run the target.
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) struct CargoTargetSpec {
|
pub(crate) struct CargoTargetSpec {
|
||||||
pub(crate) package: String,
|
pub(crate) package: String,
|
||||||
pub(crate) target: String,
|
pub(crate) target: String,
|
||||||
|
|
|
@ -393,28 +393,37 @@ pub fn handle_runnables(
|
||||||
}
|
}
|
||||||
res.push(to_lsp_runnable(&world, file_id, runnable)?);
|
res.push(to_lsp_runnable(&world, file_id, runnable)?);
|
||||||
}
|
}
|
||||||
let mut check_args = vec!["check".to_string()];
|
// Add `cargo check` and `cargo test` for the whole package
|
||||||
let label;
|
|
||||||
match CargoTargetSpec::for_file(&world, file_id)? {
|
match CargoTargetSpec::for_file(&world, file_id)? {
|
||||||
Some(spec) => {
|
Some(spec) => {
|
||||||
label = format!("cargo check -p {}", spec.package);
|
for &cmd in ["check", "test"].iter() {
|
||||||
spec.push_to(&mut check_args);
|
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 => {
|
None => {
|
||||||
label = "cargo check --all".to_string();
|
res.push(req::Runnable {
|
||||||
check_args.push("--all".to_string())
|
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)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,24 +87,15 @@ fn foo() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": [
|
"args": ["check", "--workspace"],
|
||||||
"check",
|
|
||||||
"--all"
|
|
||||||
],
|
|
||||||
"extraArgs": [],
|
"extraArgs": [],
|
||||||
"bin": "cargo",
|
"bin": "cargo",
|
||||||
"env": {},
|
"env": {},
|
||||||
"cwd": null,
|
"cwd": null,
|
||||||
"label": "cargo check --all",
|
"label": "cargo check --workspace",
|
||||||
"range": {
|
"range": {
|
||||||
"end": {
|
"end": { "character": 0, "line": 0 },
|
||||||
"character": 0,
|
"start": { "character": 0, "line": 0 }
|
||||||
"line": 0
|
|
||||||
},
|
|
||||||
"start": {
|
|
||||||
"character": 0,
|
|
||||||
"line": 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
|
@ -145,42 +136,42 @@ fn main() {}
|
||||||
server.request::<Runnables>(
|
server.request::<Runnables>(
|
||||||
RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None },
|
RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None },
|
||||||
json!([
|
json!([
|
||||||
{
|
{
|
||||||
"args": [ "test", "--package", "foo", "--test", "spam" ],
|
"args": [ "test", "--package", "foo", "--test", "spam" ],
|
||||||
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
|
"extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
|
||||||
"bin": "cargo",
|
"bin": "cargo",
|
||||||
"env": { "RUST_BACKTRACE": "short" },
|
"env": { "RUST_BACKTRACE": "short" },
|
||||||
"label": "test test_eggs",
|
"label": "test test_eggs",
|
||||||
"range": {
|
"range": {
|
||||||
"end": { "character": 17, "line": 1 },
|
"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": {},
|
|
||||||
"cwd": server.path().join("foo"),
|
|
||||||
"label": "cargo check -p foo",
|
|
||||||
"range": {
|
|
||||||
"end": {
|
|
||||||
"character": 0,
|
|
||||||
"line": 0
|
|
||||||
},
|
},
|
||||||
"start": {
|
"cwd": server.path().join("foo")
|
||||||
"character": 0,
|
},
|
||||||
"line": 0
|
{
|
||||||
}
|
"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…
Add table
Add a link
Reference in a new issue