aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-26 09:41:22 +0100
committerGitHub <[email protected]>2020-04-26 09:41:22 +0100
commitd22d88f0dc5bd17f60186fa49aa43bc82c7fa79b (patch)
tree90f8186a9fba134e0661c811bf0fe09672508c0e
parentfe99a29ad1226dd3f6801ea4bdb575506324be07 (diff)
parent5ef0f44499321ff2e8de8daf35c3ea2015c89375 (diff)
Merge #4154
4154: Add `cargo test` to the list of Run commands r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/rust-analyzer/src/cargo_target_spec.rs1
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs41
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs83
3 files changed, 63 insertions, 62 deletions
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs
index c2ece49f4..10c25666a 100644
--- a/crates/rust-analyzer/src/cargo_target_spec.rs
+++ b/crates/rust-analyzer/src/cargo_target_spec.rs
@@ -9,6 +9,7 @@ use crate::{world::WorldSnapshot, Result};
9/// 9///
10/// We use it to cook up the set of cli args we need to pass to Cargo to 10/// We use it to cook up the set of cli args we need to pass to Cargo to
11/// build/test/run the target. 11/// build/test/run the target.
12#[derive(Clone)]
12pub(crate) struct CargoTargetSpec { 13pub(crate) struct CargoTargetSpec {
13 pub(crate) package: String, 14 pub(crate) package: String,
14 pub(crate) target: String, 15 pub(crate) target: String,
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index e87e8db5d..6caaf5f88 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -393,28 +393,37 @@ pub fn handle_runnables(
393 } 393 }
394 res.push(to_lsp_runnable(&world, file_id, runnable)?); 394 res.push(to_lsp_runnable(&world, file_id, runnable)?);
395 } 395 }
396 let mut check_args = vec!["check".to_string()]; 396 // Add `cargo check` and `cargo test` for the whole package
397 let label;
398 match CargoTargetSpec::for_file(&world, file_id)? { 397 match CargoTargetSpec::for_file(&world, file_id)? {
399 Some(spec) => { 398 Some(spec) => {
400 label = format!("cargo check -p {}", spec.package); 399 for &cmd in ["check", "test"].iter() {
401 spec.push_to(&mut check_args); 400 res.push(req::Runnable {
401 range: Default::default(),
402 label: format!("cargo {} -p {}", cmd, spec.package),
403 bin: "cargo".to_string(),
404 args: {
405 let mut args = vec![cmd.to_string()];
406 spec.clone().push_to(&mut args);
407 args
408 },
409 extra_args: Vec::new(),
410 env: FxHashMap::default(),
411 cwd: workspace_root.map(|root| root.to_owned()),
412 })
413 }
402 } 414 }
403 None => { 415 None => {
404 label = "cargo check --all".to_string(); 416 res.push(req::Runnable {
405 check_args.push("--all".to_string()) 417 range: Default::default(),
418 label: "cargo check --workspace".to_string(),
419 bin: "cargo".to_string(),
420 args: vec!["check".to_string(), "--workspace".to_string()],
421 extra_args: Vec::new(),
422 env: FxHashMap::default(),
423 cwd: workspace_root.map(|root| root.to_owned()),
424 });
406 } 425 }
407 } 426 }
408 // Always add `cargo check`.
409 res.push(req::Runnable {
410 range: Default::default(),
411 label,
412 bin: "cargo".to_string(),
413 args: check_args,
414 extra_args: Vec::new(),
415 env: FxHashMap::default(),
416 cwd: workspace_root.map(|root| root.to_owned()),
417 });
418 Ok(res) 427 Ok(res)
419} 428}
420 429
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index b31533e5e..f6245ddd4 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -87,24 +87,15 @@ fn foo() {
87 } 87 }
88 }, 88 },
89 { 89 {
90 "args": [ 90 "args": ["check", "--workspace"],
91 "check",
92 "--all"
93 ],
94 "extraArgs": [], 91 "extraArgs": [],
95 "bin": "cargo", 92 "bin": "cargo",
96 "env": {}, 93 "env": {},
97 "cwd": null, 94 "cwd": null,
98 "label": "cargo check --all", 95 "label": "cargo check --workspace",
99 "range": { 96 "range": {
100 "end": { 97 "end": { "character": 0, "line": 0 },
101 "character": 0, 98 "start": { "character": 0, "line": 0 }
102 "line": 0
103 },
104 "start": {
105 "character": 0,
106 "line": 0
107 }
108 } 99 }
109 } 100 }
110 ]), 101 ]),
@@ -145,42 +136,42 @@ fn main() {}
145 server.request::<Runnables>( 136 server.request::<Runnables>(
146 RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None }, 137 RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None },
147 json!([ 138 json!([
148 { 139 {
149 "args": [ "test", "--package", "foo", "--test", "spam" ], 140 "args": [ "test", "--package", "foo", "--test", "spam" ],
150 "extraArgs": [ "test_eggs", "--exact", "--nocapture" ], 141 "extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
151 "bin": "cargo", 142 "bin": "cargo",
152 "env": { "RUST_BACKTRACE": "short" }, 143 "env": { "RUST_BACKTRACE": "short" },
153 "label": "test test_eggs", 144 "label": "test test_eggs",
154 "range": { 145 "range": {
155 "end": { "character": 17, "line": 1 }, 146 "end": { "character": 17, "line": 1 },
156 "start": { "character": 0, "line": 0 } 147 "start": { "character": 0, "line": 0 }
148 },
149 "cwd": server.path().join("foo")
157 }, 150 },
158 "cwd": server.path().join("foo") 151 {
159 }, 152 "args": [ "check", "--package", "foo", "--test", "spam" ],
160 { 153 "extraArgs": [],
161 "args": [ 154 "bin": "cargo",
162 "check", 155 "env": {},
163 "--package", 156 "label": "cargo check -p foo",
164 "foo", 157 "range": {
165 "--test", 158 "end": { "character": 0, "line": 0 },
166 "spam" 159 "start": { "character": 0, "line": 0 }
167 ],
168 "extraArgs": [],
169 "bin": "cargo",
170 "env": {},
171 "cwd": server.path().join("foo"),
172 "label": "cargo check -p foo",
173 "range": {
174 "end": {
175 "character": 0,
176 "line": 0
177 }, 160 },
178 "start": { 161 "cwd": server.path().join("foo")
179 "character": 0, 162 },
180 "line": 0 163 {
181 } 164 "args": [ "test", "--package", "foo", "--test", "spam" ],
165 "extraArgs": [],
166 "bin": "cargo",
167 "env": {},
168 "label": "cargo test -p foo",
169 "range": {
170 "end": { "character": 0, "line": 0 },
171 "start": { "character": 0, "line": 0 }
172 },
173 "cwd": server.path().join("foo")
182 } 174 }
183 }
184 ]), 175 ]),
185 ); 176 );
186} 177}