aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/Cargo.toml1
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs11
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs14
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs14
4 files changed, 18 insertions, 22 deletions
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 2e49448cc..65b487db3 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -48,7 +48,6 @@ hir = { path = "../ra_hir", package = "ra_hir" }
48hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } 48hir_def = { path = "../ra_hir_def", package = "ra_hir_def" }
49hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } 49hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" }
50ra_proc_macro_srv = { path = "../ra_proc_macro_srv" } 50ra_proc_macro_srv = { path = "../ra_proc_macro_srv" }
51ra_toolchain = { path = "../ra_toolchain" }
52 51
53[target.'cfg(windows)'.dependencies] 52[target.'cfg(windows)'.dependencies]
54winapi = "0.3.8" 53winapi = "0.3.8"
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index acb1dacb6..173c23b9e 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -121,12 +121,21 @@ pub struct RunnablesParams {
121 pub position: Option<Position>, 121 pub position: Option<Position>,
122} 122}
123 123
124// Must strictly correspond to the executable name
125#[derive(Serialize, Deserialize, Debug)]
126#[serde(rename_all = "lowercase")]
127pub enum RunnableKind {
128 Cargo,
129 Rustc,
130 Rustup,
131}
132
124#[derive(Deserialize, Serialize, Debug)] 133#[derive(Deserialize, Serialize, Debug)]
125#[serde(rename_all = "camelCase")] 134#[serde(rename_all = "camelCase")]
126pub struct Runnable { 135pub struct Runnable {
127 pub range: Range, 136 pub range: Range,
128 pub label: String, 137 pub label: String,
129 pub bin: String, 138 pub kind: RunnableKind,
130 pub args: Vec<String>, 139 pub args: Vec<String>,
131 pub extra_args: Vec<String>, 140 pub extra_args: Vec<String>,
132 pub env: FxHashMap<String, String>, 141 pub env: FxHashMap<String, String>,
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index d42cfa300..bc7c7f1ef 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -40,7 +40,6 @@ use crate::{
40 world::WorldSnapshot, 40 world::WorldSnapshot,
41 LspError, Result, 41 LspError, Result,
42}; 42};
43use anyhow::Context;
44 43
45pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> { 44pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
46 let _p = profile("handle_analyzer_status"); 45 let _p = profile("handle_analyzer_status");
@@ -427,7 +426,7 @@ pub fn handle_runnables(
427 res.push(lsp_ext::Runnable { 426 res.push(lsp_ext::Runnable {
428 range: Default::default(), 427 range: Default::default(),
429 label: format!("cargo {} -p {}", cmd, spec.package), 428 label: format!("cargo {} -p {}", cmd, spec.package),
430 bin: cargo_path()?, 429 kind: lsp_ext::RunnableKind::Cargo,
431 args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()], 430 args: vec![cmd.to_string(), "--package".to_string(), spec.package.clone()],
432 extra_args: Vec::new(), 431 extra_args: Vec::new(),
433 env: FxHashMap::default(), 432 env: FxHashMap::default(),
@@ -439,7 +438,7 @@ pub fn handle_runnables(
439 res.push(lsp_ext::Runnable { 438 res.push(lsp_ext::Runnable {
440 range: Default::default(), 439 range: Default::default(),
441 label: "cargo check --workspace".to_string(), 440 label: "cargo check --workspace".to_string(),
442 bin: cargo_path()?, 441 kind: lsp_ext::RunnableKind::Cargo,
443 args: vec!["check".to_string(), "--workspace".to_string()], 442 args: vec!["check".to_string(), "--workspace".to_string()],
444 extra_args: Vec::new(), 443 extra_args: Vec::new(),
445 env: FxHashMap::default(), 444 env: FxHashMap::default(),
@@ -450,13 +449,6 @@ pub fn handle_runnables(
450 Ok(res) 449 Ok(res)
451} 450}
452 451
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
460pub fn handle_completion( 452pub fn handle_completion(
461 world: WorldSnapshot, 453 world: WorldSnapshot,
462 params: lsp_types::CompletionParams, 454 params: lsp_types::CompletionParams,
@@ -994,7 +986,7 @@ fn to_lsp_runnable(
994 Ok(lsp_ext::Runnable { 986 Ok(lsp_ext::Runnable {
995 range: to_proto::range(&line_index, runnable.range), 987 range: to_proto::range(&line_index, runnable.range),
996 label, 988 label,
997 bin: cargo_path()?, 989 kind: lsp_ext::RunnableKind::Cargo,
998 args, 990 args,
999 extra_args, 991 extra_args,
1000 env: { 992 env: {
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index a31580c86..8b473ff74 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -58,10 +58,6 @@ 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
65#[test] 61#[test]
66fn test_runnables_no_project() { 62fn test_runnables_no_project() {
67 if skip_slow_tests() { 63 if skip_slow_tests() {
@@ -83,7 +79,7 @@ fn foo() {
83 { 79 {
84 "args": [ "test" ], 80 "args": [ "test" ],
85 "extraArgs": [ "foo", "--nocapture" ], 81 "extraArgs": [ "foo", "--nocapture" ],
86 "bin": cargo_path(), 82 "kind": "cargo",
87 "env": { "RUST_BACKTRACE": "short" }, 83 "env": { "RUST_BACKTRACE": "short" },
88 "cwd": null, 84 "cwd": null,
89 "label": "test foo", 85 "label": "test foo",
@@ -95,7 +91,7 @@ fn foo() {
95 { 91 {
96 "args": ["check", "--workspace"], 92 "args": ["check", "--workspace"],
97 "extraArgs": [], 93 "extraArgs": [],
98 "bin": cargo_path(), 94 "kind": "cargo",
99 "env": {}, 95 "env": {},
100 "cwd": null, 96 "cwd": null,
101 "label": "cargo check --workspace", 97 "label": "cargo check --workspace",
@@ -145,7 +141,7 @@ fn main() {}
145 { 141 {
146 "args": [ "test", "--package", "foo", "--test", "spam" ], 142 "args": [ "test", "--package", "foo", "--test", "spam" ],
147 "extraArgs": [ "test_eggs", "--exact", "--nocapture" ], 143 "extraArgs": [ "test_eggs", "--exact", "--nocapture" ],
148 "bin": cargo_path(), 144 "kind": "cargo",
149 "env": { "RUST_BACKTRACE": "short" }, 145 "env": { "RUST_BACKTRACE": "short" },
150 "label": "test test_eggs", 146 "label": "test test_eggs",
151 "range": { 147 "range": {
@@ -157,7 +153,7 @@ fn main() {}
157 { 153 {
158 "args": [ "check", "--package", "foo" ], 154 "args": [ "check", "--package", "foo" ],
159 "extraArgs": [], 155 "extraArgs": [],
160 "bin": cargo_path(), 156 "kind": "cargo",
161 "env": {}, 157 "env": {},
162 "label": "cargo check -p foo", 158 "label": "cargo check -p foo",
163 "range": { 159 "range": {
@@ -169,7 +165,7 @@ fn main() {}
169 { 165 {
170 "args": [ "test", "--package", "foo" ], 166 "args": [ "test", "--package", "foo" ],
171 "extraArgs": [], 167 "extraArgs": [],
172 "bin": cargo_path(), 168 "kind": "cargo",
173 "env": {}, 169 "env": {},
174 "label": "cargo test -p foo", 170 "label": "cargo test -p foo",
175 "range": { 171 "range": {