From 7c7cfc5f04c51ed1e31b6a3091efc3941b3383c2 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Sat, 13 Apr 2019 19:45:21 +0200 Subject: Sends cwd info for runnables and code lenses --- crates/ra_lsp_server/src/main_loop/handlers.rs | 5 +++++ crates/ra_lsp_server/src/req.rs | 1 + crates/ra_lsp_server/src/server_world.rs | 7 ++++++- crates/ra_lsp_server/tests/heavy_tests/main.rs | 6 +++++- crates/ra_lsp_server/tests/heavy_tests/support.rs | 6 +++++- 5 files changed, 22 insertions(+), 3 deletions(-) (limited to 'crates/ra_lsp_server') 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( let line_index = world.analysis().file_line_index(file_id); let offset = params.position.map(|it| it.conv_with(&line_index)); let mut res = Vec::new(); + let workspace_root = world.workspace_root_for(file_id); for runnable in world.analysis().runnables(file_id)? { if let Some(offset) = offset { if !runnable.range.contains_inclusive(offset) { @@ -287,6 +288,7 @@ pub fn handle_runnables( m.insert("RUST_BACKTRACE".to_string(), "short".to_string()); m }, + cwd: workspace_root.map(|root| root.to_string_lossy().to_string()), }; res.push(r); } @@ -309,6 +311,7 @@ pub fn handle_runnables( bin: "cargo".to_string(), args: check_args, env: FxHashMap::default(), + cwd: workspace_root.map(|root| root.to_string_lossy().to_string()), }); Ok(res) } @@ -627,6 +630,7 @@ pub fn handle_code_lens( let line_index = world.analysis().file_line_index(file_id); let mut lenses: Vec = Default::default(); + let workspace_root = world.workspace_root_for(file_id); // Gather runnables for runnable in world.analysis().runnables(file_id)? { @@ -647,6 +651,7 @@ pub fn handle_code_lens( bin: "cargo".into(), args, env: Default::default(), + cwd: workspace_root.map(|root| root.to_string_lossy().to_string()), }; 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 { pub bin: String, pub args: Vec, pub env: FxHashMap, + pub cwd: Option, } #[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 @@ use std::{ - path::PathBuf, + path::{Path, PathBuf}, sync::Arc, }; @@ -195,4 +195,9 @@ impl ServerWorld { res.push_str(&self.analysis.status()); res } + + pub fn workspace_root_for(&self, file_id: FileId) -> Option<&Path> { + let path = self.vfs.read().file2path(VfsFile(file_id.0.into())); + self.workspaces.iter().find_map(|ws| ws.workspace_root_for(&path)) + } } 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() { "args": [ "test", "--", "foo", "--nocapture" ], "bin": "cargo", "env": { "RUST_BACKTRACE": "short" }, + "cwd": null, "label": "test foo", "range": { "end": { "character": 1, "line": 2 }, @@ -75,6 +76,7 @@ fn foo() { ], "bin": "cargo", "env": {}, + "cwd": null, "label": "cargo check --all", "range": { "end": { @@ -123,7 +125,8 @@ fn test_eggs() {} "range": { "end": { "character": 17, "line": 1 }, "start": { "character": 0, "line": 0 } - } + }, + "cwd": server.path() }, { "args": [ @@ -135,6 +138,7 @@ fn test_eggs() {} ], "bin": "cargo", "env": {}, + "cwd": server.path(), "label": "cargo check -p foo", "range": { "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 @@ use std::{ cell::{Cell, RefCell}, fs, - path::PathBuf, + path::{Path, PathBuf}, sync::Once, time::Duration, }; @@ -177,6 +177,10 @@ impl Server { fn send_notification(&self, not: RawNotification) { self.worker.as_ref().unwrap().sender().send(RawMessage::Notification(not)).unwrap(); } + + pub fn path(&self) -> &Path { + self.dir.path() + } } impl Drop for Server { -- cgit v1.2.3