aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorveetaha <[email protected]>2020-05-23 14:31:56 +0100
committerveetaha <[email protected]>2020-05-31 01:10:23 +0100
commita419cedb1cc661349a022262c8b03993e063252f (patch)
tree0ecbd647606acdd5680c61f6b2d03b870a2c3a03
parent030d78345fa79af07f8ebd89a9d244576fac992b (diff)
Fix tests, apply code review proposals
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ra_proc_macro_srv/Cargo.toml1
-rw-r--r--crates/ra_proc_macro_srv/src/tests/utils.rs3
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs17
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs14
5 files changed, 22 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7de784c1c..e1da335f5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1119,6 +1119,7 @@ dependencies = [
1119 "memmap", 1119 "memmap",
1120 "ra_mbe", 1120 "ra_mbe",
1121 "ra_proc_macro", 1121 "ra_proc_macro",
1122 "ra_toolchain",
1122 "ra_tt", 1123 "ra_tt",
1123 "serde_derive", 1124 "serde_derive",
1124 "test_utils", 1125 "test_utils",
diff --git a/crates/ra_proc_macro_srv/Cargo.toml b/crates/ra_proc_macro_srv/Cargo.toml
index bb3003278..582102945 100644
--- a/crates/ra_proc_macro_srv/Cargo.toml
+++ b/crates/ra_proc_macro_srv/Cargo.toml
@@ -22,3 +22,4 @@ cargo_metadata = "0.10.0"
22difference = "2.0.0" 22difference = "2.0.0"
23# used as proc macro test target 23# used as proc macro test target
24serde_derive = "1.0.106" 24serde_derive = "1.0.106"
25ra_toolchain = { path = "../ra_toolchain" }
diff --git a/crates/ra_proc_macro_srv/src/tests/utils.rs b/crates/ra_proc_macro_srv/src/tests/utils.rs
index 84348b5de..8d85f2d8a 100644
--- a/crates/ra_proc_macro_srv/src/tests/utils.rs
+++ b/crates/ra_proc_macro_srv/src/tests/utils.rs
@@ -2,7 +2,6 @@
2 2
3use crate::dylib; 3use crate::dylib;
4use crate::ProcMacroSrv; 4use crate::ProcMacroSrv;
5pub use difference::Changeset as __Changeset;
6use ra_proc_macro::ListMacrosTask; 5use ra_proc_macro::ListMacrosTask;
7use std::str::FromStr; 6use std::str::FromStr;
8use test_utils::assert_eq_text; 7use test_utils::assert_eq_text;
@@ -13,7 +12,7 @@ mod fixtures {
13 12
14 // Use current project metadata to get the proc-macro dylib path 13 // Use current project metadata to get the proc-macro dylib path
15 pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf { 14 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())
17 .args(&["check", "--message-format", "json"]) 16 .args(&["check", "--message-format", "json"])
18 .output() 17 .output()
19 .unwrap() 18 .unwrap()
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 1b5b3325c..d42cfa300 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -427,7 +427,7 @@ pub fn handle_runnables(
427 res.push(lsp_ext::Runnable { 427 res.push(lsp_ext::Runnable {
428 range: Default::default(), 428 range: Default::default(),
429 label: format!("cargo {} -p {}", cmd, spec.package), 429 label: format!("cargo {} -p {}", cmd, spec.package),
430 bin: "cargo".to_string(), 430 bin: cargo_path()?,
431 args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()], 431 args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()],
432 extra_args: Vec::new(), 432 extra_args: Vec::new(),
433 env: FxHashMap::default(), 433 env: FxHashMap::default(),
@@ -439,7 +439,7 @@ pub fn handle_runnables(
439 res.push(lsp_ext::Runnable { 439 res.push(lsp_ext::Runnable {
440 range: Default::default(), 440 range: Default::default(),
441 label: "cargo check --workspace".to_string(), 441 label: "cargo check --workspace".to_string(),
442 bin: "cargo".to_string(), 442 bin: cargo_path()?,
443 args: vec!["check".to_string(), "--workspace".to_string()], 443 args: vec!["check".to_string(), "--workspace".to_string()],
444 extra_args: Vec::new(), 444 extra_args: Vec::new(),
445 env: FxHashMap::default(), 445 env: FxHashMap::default(),
@@ -450,6 +450,13 @@ pub fn handle_runnables(
450 Ok(res) 450 Ok(res)
451} 451}
452 452
453fn cargo_path() -> Result<String> {
454 Ok(ra_toolchain::cargo()
455 .to_str()
456 .context("Path to `cargo` executable contains invalid UTF8 characters")?
457 .to_owned())
458}
459
453pub fn handle_completion( 460pub fn handle_completion(
454 world: WorldSnapshot, 461 world: WorldSnapshot,
455 params: lsp_types::CompletionParams, 462 params: lsp_types::CompletionParams,
@@ -983,15 +990,11 @@ fn to_lsp_runnable(
983 target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t)) 990 target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t))
984 } 991 }
985 }; 992 };
986 let cargo_path = ra_toolchain::cargo()
987 .to_str()
988 .context("Path to cargo executable contains invalid UTF8 characters")?
989 .to_owned();
990 993
991 Ok(lsp_ext::Runnable { 994 Ok(lsp_ext::Runnable {
992 range: to_proto::range(&line_index, runnable.range), 995 range: to_proto::range(&line_index, runnable.range),
993 label, 996 label,
994 bin: cargo_path, 997 bin: cargo_path()?,
995 args, 998 args,
996 extra_args, 999 extra_args,
997 env: { 1000 env: {
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index 405ddb362..a31580c86 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -58,6 +58,10 @@ use std::collections::Spam;
58 eprintln!("completion took {:?}", completion_start.elapsed()); 58 eprintln!("completion took {:?}", completion_start.elapsed());
59} 59}
60 60
61fn cargo_path() -> String {
62 ra_toolchain::cargo().to_str().unwrap().to_owned()
63}
64
61#[test] 65#[test]
62fn test_runnables_no_project() { 66fn test_runnables_no_project() {
63 if skip_slow_tests() { 67 if skip_slow_tests() {
@@ -79,7 +83,7 @@ fn foo() {
79 { 83 {
80 "args": [ "test" ], 84 "args": [ "test" ],
81 "extraArgs": [ "foo", "--nocapture" ], 85 "extraArgs": [ "foo", "--nocapture" ],
82 "bin": "cargo", 86 "bin": cargo_path(),
83 "env": { "RUST_BACKTRACE": "short" }, 87 "env": { "RUST_BACKTRACE": "short" },
84 "cwd": null, 88 "cwd": null,
85 "label": "test foo", 89 "label": "test foo",
@@ -91,7 +95,7 @@ fn foo() {
91 { 95 {
92 "args": ["check", "--workspace"], 96 "args": ["check", "--workspace"],
93 "extraArgs": [], 97 "extraArgs": [],
94 "bin": "cargo", 98 "bin": cargo_path(),
95 "env": {}, 99 "env": {},
96 "cwd": null, 100 "cwd": null,
97 "label": "cargo check --workspace", 101 "label": "cargo check --workspace",
@@ -141,7 +145,7 @@ fn main() {}
141 { 145 {
142 "args": [ "test", "--package", "foo", "--test", "spam" ], 146 "args": [ "test", "--package", "foo", "--test", "spam" ],
143 "extraArgs": [ "test_eggs", "--exact", "--nocapture" ], 147 "extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
144 "bin": "cargo", 148 "bin": cargo_path(),
145 "env": { "RUST_BACKTRACE": "short" }, 149 "env": { "RUST_BACKTRACE": "short" },
146 "label": "test test_eggs", 150 "label": "test test_eggs",
147 "range": { 151 "range": {
@@ -153,7 +157,7 @@ fn main() {}
153 { 157 {
154 "args": [ "check", "--package", "foo" ], 158 "args": [ "check", "--package", "foo" ],
155 "extraArgs": [], 159 "extraArgs": [],
156 "bin": "cargo", 160 "bin": cargo_path(),
157 "env": {}, 161 "env": {},
158 "label": "cargo check -p foo", 162 "label": "cargo check -p foo",
159 "range": { 163 "range": {
@@ -165,7 +169,7 @@ fn main() {}
165 { 169 {
166 "args": [ "test", "--package", "foo" ], 170 "args": [ "test", "--package", "foo" ],
167 "extraArgs": [], 171 "extraArgs": [],
168 "bin": "cargo", 172 "bin": cargo_path(),
169 "env": {}, 173 "env": {},
170 "label": "cargo test -p foo", 174 "label": "cargo test -p foo",
171 "range": { 175 "range": {