aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs3
-rw-r--r--crates/ra_project_model/src/lib.rs12
-rw-r--r--editors/code/src/commands/runnables.ts3
8 files changed, 38 insertions, 5 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 {
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 81cb506b7..71976071f 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -19,6 +19,7 @@ use crate::Result;
19pub struct CargoWorkspace { 19pub struct CargoWorkspace {
20 packages: Arena<Package, PackageData>, 20 packages: Arena<Package, PackageData>,
21 targets: Arena<Target, TargetData>, 21 targets: Arena<Target, TargetData>,
22 pub(crate) workspace_root: PathBuf,
22} 23}
23 24
24#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 25#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -165,7 +166,7 @@ impl CargoWorkspace {
165 } 166 }
166 } 167 }
167 168
168 Ok(CargoWorkspace { packages, targets }) 169 Ok(CargoWorkspace { packages, targets, workspace_root: meta.workspace_root })
169 } 170 }
170 171
171 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + 'a { 172 pub fn packages<'a>(&'a self) -> impl Iterator<Item = Package> + 'a {
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 3bad4f8d3..63eb7041e 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -255,6 +255,18 @@ impl ProjectWorkspace {
255 } 255 }
256 crate_graph 256 crate_graph
257 } 257 }
258
259 pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
260 match self {
261 ProjectWorkspace::Cargo { cargo, .. } => {
262 Some(cargo.workspace_root.as_ref()).filter(|root| path.starts_with(root))
263 }
264 ProjectWorkspace::Json { project: JsonProject { roots, .. } } => roots
265 .iter()
266 .find(|root| path.starts_with(&root.path))
267 .map(|root| root.path.as_ref()),
268 }
269 }
258} 270}
259 271
260fn find_rust_project_json(path: &Path) -> Option<PathBuf> { 272fn find_rust_project_json(path: &Path) -> Option<PathBuf> {
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts
index 3589edcee..c4df24c79 100644
--- a/editors/code/src/commands/runnables.ts
+++ b/editors/code/src/commands/runnables.ts
@@ -17,6 +17,7 @@ interface Runnable {
17 bin: string; 17 bin: string;
18 args: string[]; 18 args: string[];
19 env: { [index: string]: string }; 19 env: { [index: string]: string };
20 cwd?: string;
20} 21}
21 22
22class RunnableQuickPick implements vscode.QuickPickItem { 23class RunnableQuickPick implements vscode.QuickPickItem {
@@ -49,7 +50,7 @@ function createTask(spec: Runnable): vscode.Task {
49 }; 50 };
50 51
51 const execOption: vscode.ShellExecutionOptions = { 52 const execOption: vscode.ShellExecutionOptions = {
52 cwd: '.', 53 cwd: spec.cwd || '.',
53 env: definition.env 54 env: definition.env
54 }; 55 };
55 const exec = new vscode.ShellExecution( 56 const exec = new vscode.ShellExecution(