Skip to content

Commit 1d1eea2

Browse files
committed
Slightly more robust cargo watcher root search
1 parent 19eb7fa commit 1d1eea2

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

crates/ra_lsp_server/src/world.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl WorldState {
7474
lru_capacity: Option<usize>,
7575
exclude_globs: &[Glob],
7676
watch: Watch,
77-
options: Options,
77+
mut options: Options,
7878
feature_flags: FeatureFlags,
7979
) -> WorldState {
8080
let mut change = AnalysisChange::new();
@@ -132,8 +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-
CheckWatcher::new(&options.cargo_watch, folder_roots.first().cloned().unwrap());
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.clone(),
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+
};
137149

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

crates/ra_project_model/src/cargo_workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::Result;
2121
pub struct CargoWorkspace {
2222
packages: Arena<Package, PackageData>,
2323
targets: Arena<Target, TargetData>,
24-
pub(crate) workspace_root: PathBuf,
24+
pub workspace_root: PathBuf,
2525
}
2626

2727
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)