Skip to content

Commit 480c449

Browse files
committed
Disable cargo checking in workspaces with no cargo projects
1 parent d6da18e commit 480c449

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

crates/ra_cargo_watch/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ impl CheckWatcher {
5858
CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle), shared }
5959
}
6060

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+
6167
/// Schedule a re-start of the cargo check worker.
6268
pub fn update(&self) {
6369
if let Some(cmd_send) = &self.cmd_send {

crates/ra_lsp_server/src/world.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ impl WorldState {
132132
change.set_crate_graph(crate_graph);
133133

134134
// FIXME: Figure out the multi-workspace situation
135-
let check_watcher = {
136-
let first_workspace = workspaces.first().unwrap();
137-
let cargo_project_root = match first_workspace {
138-
ProjectWorkspace::Cargo { cargo, .. } => cargo.workspace_root().to_path_buf(),
139-
ProjectWorkspace::Json { .. } => {
140-
log::warn!(
141-
"Cargo check watching only supported for cargo workspaces, disabling"
142-
);
143-
options.cargo_watch.enable = false;
144-
PathBuf::new()
145-
}
146-
};
147-
CheckWatcher::new(&options.cargo_watch, cargo_project_root)
148-
};
135+
let check_watcher = workspaces
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+
});
149149

150150
let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags);
151151
analysis_host.apply_change(change);

0 commit comments

Comments
 (0)