diff options
author | Roberto Vidal <[email protected]> | 2019-04-13 18:45:21 +0100 |
---|---|---|
committer | Roberto Vidal <[email protected]> | 2019-04-14 09:04:38 +0100 |
commit | 7c7cfc5f04c51ed1e31b6a3091efc3941b3383c2 (patch) | |
tree | 0bc4d2f3afefb504509676388016da52598fe1dd /crates/ra_lsp_server/src | |
parent | 3507bcb97aaaafba10d55c101bd295f3ab4fed4f (diff) |
Sends cwd info for runnables and code lenses
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 5 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 7 |
3 files changed, 12 insertions, 1 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 @@ | |||
1 | use std::{ | 1 | use 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 | } |