aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
authorRoberto Vidal <[email protected]>2019-04-13 18:45:21 +0100
committerRoberto Vidal <[email protected]>2019-04-14 09:04:38 +0100
commit7c7cfc5f04c51ed1e31b6a3091efc3941b3383c2 (patch)
tree0bc4d2f3afefb504509676388016da52598fe1dd /crates/ra_lsp_server
parent3507bcb97aaaafba10d55c101bd295f3ab4fed4f (diff)
Sends cwd info for runnables and code lenses
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs5
-rw-r--r--crates/ra_lsp_server/src/req.rs1
-rw-r--r--crates/ra_lsp_server/src/server_world.rs7
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs6
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/support.rs6
5 files changed, 22 insertions, 3 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index b96deb061..41d1f759f 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -263,6 +263,7 @@ pub fn handle_runnables(
263 let line_index = world.analysis().file_line_index(file_id); 263 let line_index = world.analysis().file_line_index(file_id);
264 let offset = params.position.map(|it| it.conv_with(&line_index)); 264 let offset = params.position.map(|it| it.conv_with(&line_index));
265 let mut res = Vec::new(); 265 let mut res = Vec::new();
266 let workspace_root = world.workspace_root_for(file_id);
266 for runnable in world.analysis().runnables(file_id)? { 267 for runnable in world.analysis().runnables(file_id)? {
267 if let Some(offset) = offset { 268 if let Some(offset) = offset {
268 if !runnable.range.contains_inclusive(offset) { 269 if !runnable.range.contains_inclusive(offset) {
@@ -287,6 +288,7 @@ pub fn handle_runnables(
287 m.insert("RUST_BACKTRACE".to_string(), "short".to_string()); 288 m.insert("RUST_BACKTRACE".to_string(), "short".to_string());
288 m 289 m
289 }, 290 },
291 cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
290 }; 292 };
291 res.push(r); 293 res.push(r);
292 } 294 }
@@ -309,6 +311,7 @@ pub fn handle_runnables(
309 bin: "cargo".to_string(), 311 bin: "cargo".to_string(),
310 args: check_args, 312 args: check_args,
311 env: FxHashMap::default(), 313 env: FxHashMap::default(),
314 cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
312 }); 315 });
313 Ok(res) 316 Ok(res)
314} 317}
@@ -627,6 +630,7 @@ pub fn handle_code_lens(
627 let line_index = world.analysis().file_line_index(file_id); 630 let line_index = world.analysis().file_line_index(file_id);
628 631
629 let mut lenses: Vec<CodeLens> = Default::default(); 632 let mut lenses: Vec<CodeLens> = Default::default();
633 let workspace_root = world.workspace_root_for(file_id);
630 634
631 // Gather runnables 635 // Gather runnables
632 for runnable in world.analysis().runnables(file_id)? { 636 for runnable in world.analysis().runnables(file_id)? {
@@ -647,6 +651,7 @@ pub fn handle_code_lens(
647 bin: "cargo".into(), 651 bin: "cargo".into(),
648 args, 652 args,
649 env: Default::default(), 653 env: Default::default(),
654 cwd: workspace_root.map(|root| root.to_string_lossy().to_string()),
650 }; 655 };
651 656
652 let lens = CodeLens { 657 let lens = CodeLens {
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs
index e0571fd78..4f35ab9b5 100644
--- a/crates/ra_lsp_server/src/req.rs
+++ b/crates/ra_lsp_server/src/req.rs
@@ -163,6 +163,7 @@ pub struct Runnable {
163 pub bin: String, 163 pub bin: String,
164 pub args: Vec<String>, 164 pub args: Vec<String>,
165 pub env: FxHashMap<String, String>, 165 pub env: FxHashMap<String, String>,
166 pub cwd: Option<String>,
166} 167}
167 168
168#[derive(Serialize, Debug)] 169#[derive(Serialize, Debug)]
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index 45ad8e24e..b2808b817 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -1,5 +1,5 @@
1use std::{ 1use std::{
2 path::PathBuf, 2 path::{Path, PathBuf},
3 sync::Arc, 3 sync::Arc,
4}; 4};
5 5
@@ -195,4 +195,9 @@ impl ServerWorld {
195 res.push_str(&self.analysis.status()); 195 res.push_str(&self.analysis.status());
196 res 196 res
197 } 197 }
198
199 pub fn workspace_root_for(&self, file_id: FileId) -> Option<&Path> {
200 let path = self.vfs.read().file2path(VfsFile(file_id.0.into()));
201 self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path))
202 }
198} 203}
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index 407719080..e9ce002de 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -62,6 +62,7 @@ fn foo() {
62 "args": [ "test", "--", "foo", "--nocapture" ], 62 "args": [ "test", "--", "foo", "--nocapture" ],
63 "bin": "cargo", 63 "bin": "cargo",
64 "env": { "RUST_BACKTRACE": "short" }, 64 "env": { "RUST_BACKTRACE": "short" },
65 "cwd": null,
65 "label": "test foo", 66 "label": "test foo",
66 "range": { 67 "range": {
67 "end": { "character": 1, "line": 2 }, 68 "end": { "character": 1, "line": 2 },
@@ -75,6 +76,7 @@ fn foo() {
75 ], 76 ],
76 "bin": "cargo", 77 "bin": "cargo",
77 "env": {}, 78 "env": {},
79 "cwd": null,
78 "label": "cargo check --all", 80 "label": "cargo check --all",
79 "range": { 81 "range": {
80 "end": { 82 "end": {
@@ -123,7 +125,8 @@ fn test_eggs() {}
123 "range": { 125 "range": {
124 "end": { "character": 17, "line": 1 }, 126 "end": { "character": 17, "line": 1 },
125 "start": { "character": 0, "line": 0 } 127 "start": { "character": 0, "line": 0 }
126 } 128 },
129 "cwd": server.path()
127 }, 130 },
128 { 131 {
129 "args": [ 132 "args": [
@@ -135,6 +138,7 @@ fn test_eggs() {}
135 ], 138 ],
136 "bin": "cargo", 139 "bin": "cargo",
137 "env": {}, 140 "env": {},
141 "cwd": server.path(),
138 "label": "cargo check -p foo", 142 "label": "cargo check -p foo",
139 "range": { 143 "range": {
140 "end": { 144 "end": {
diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs
index 4ea6760a1..9e115fb7f 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/support.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs
@@ -1,7 +1,7 @@
1use std::{ 1use std::{
2 cell::{Cell, RefCell}, 2 cell::{Cell, RefCell},
3 fs, 3 fs,
4 path::PathBuf, 4 path::{Path, PathBuf},
5 sync::Once, 5 sync::Once,
6 time::Duration, 6 time::Duration,
7}; 7};
@@ -177,6 +177,10 @@ impl Server {
177 fn send_notification(&self, not: RawNotification) { 177 fn send_notification(&self, not: RawNotification) {
178 self.worker.as_ref().unwrap().sender().send(RawMessage::Notification(not)).unwrap(); 178 self.worker.as_ref().unwrap().sender().send(RawMessage::Notification(not)).unwrap();
179 } 179 }
180
181 pub fn path(&self) -> &Path {
182 self.dir.path()
183 }
180} 184}
181 185
182impl Drop for Server { 186impl Drop for Server {