aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_cargo_watch/src/lib.rs6
-rw-r--r--crates/ra_lsp_server/src/world.rs16
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs6
-rw-r--r--crates/ra_project_model/src/lib.rs2
4 files changed, 26 insertions, 4 deletions
diff --git a/crates/ra_cargo_watch/src/lib.rs b/crates/ra_cargo_watch/src/lib.rs
index 9bc0fd405..cb0856aa4 100644
--- a/crates/ra_cargo_watch/src/lib.rs
+++ b/crates/ra_cargo_watch/src/lib.rs
@@ -58,6 +58,12 @@ impl CheckWatcher {
58 CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle), shared } 58 CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle), shared }
59 } 59 }
60 60
61 /// Returns a CheckWatcher that doesn't actually do anything
62 pub fn dummy() -> CheckWatcher {
63 let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new()));
64 CheckWatcher { task_recv: never(), cmd_send: None, handle: None, shared }
65 }
66
61 /// Schedule a re-start of the cargo check worker. 67 /// Schedule a re-start of the cargo check worker.
62 pub fn update(&self) { 68 pub fn update(&self) {
63 if let Some(cmd_send) = &self.cmd_send { 69 if let Some(cmd_send) = &self.cmd_send {
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs
index 121ddfd1f..c0175c726 100644
--- a/crates/ra_lsp_server/src/world.rs
+++ b/crates/ra_lsp_server/src/world.rs
@@ -132,8 +132,20 @@ impl WorldState {
132 change.set_crate_graph(crate_graph); 132 change.set_crate_graph(crate_graph);
133 133
134 // FIXME: Figure out the multi-workspace situation 134 // FIXME: Figure out the multi-workspace situation
135 let check_watcher = 135 let check_watcher = workspaces
136 CheckWatcher::new(&options.cargo_watch, folder_roots.first().cloned().unwrap()); 136 .iter()
137 .find_map(|w| match w {
138 ProjectWorkspace::Cargo { cargo, .. } => Some(cargo),
139 ProjectWorkspace::Json { .. } => None,
140 })
141 .map(|cargo| {
142 let cargo_project_root = cargo.workspace_root().to_path_buf();
143 CheckWatcher::new(&options.cargo_watch, cargo_project_root)
144 })
145 .unwrap_or_else(|| {
146 log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
147 CheckWatcher::dummy()
148 });
137 149
138 let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags); 150 let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags);
139 analysis_host.apply_change(change); 151 analysis_host.apply_change(change);
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 1b3c246c7..1832c101f 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -21,7 +21,7 @@ use crate::Result;
21pub struct CargoWorkspace { 21pub struct CargoWorkspace {
22 packages: Arena<Package, PackageData>, 22 packages: Arena<Package, PackageData>,
23 targets: Arena<Target, TargetData>, 23 targets: Arena<Target, TargetData>,
24 pub(crate) workspace_root: PathBuf, 24 workspace_root: PathBuf,
25} 25}
26 26
27#[derive(Deserialize, Clone, Debug, PartialEq, Eq)] 27#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
@@ -225,4 +225,8 @@ impl CargoWorkspace {
225 pub fn target_by_root(&self, root: &Path) -> Option<Target> { 225 pub fn target_by_root(&self, root: &Path) -> Option<Target> {
226 self.packages().filter_map(|pkg| pkg.targets(self).find(|it| it.root(self) == root)).next() 226 self.packages().filter_map(|pkg| pkg.targets(self).find(|it| it.root(self) == root)).next()
227 } 227 }
228
229 pub fn workspace_root(&self) -> &Path {
230 &self.workspace_root
231 }
228} 232}
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index b7f6a9b57..6a104e6f2 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -333,7 +333,7 @@ impl ProjectWorkspace {
333 pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> { 333 pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
334 match self { 334 match self {
335 ProjectWorkspace::Cargo { cargo, .. } => { 335 ProjectWorkspace::Cargo { cargo, .. } => {
336 Some(cargo.workspace_root.as_ref()).filter(|root| path.starts_with(root)) 336 Some(cargo.workspace_root()).filter(|root| path.starts_with(root))
337 } 337 }
338 ProjectWorkspace::Json { project: JsonProject { roots, .. } } => roots 338 ProjectWorkspace::Json { project: JsonProject { roots, .. } } => roots
339 .iter() 339 .iter()