2791: Slightly more robust cargo watcher root search r=kiljacken a=kiljacken

Fixes #2780 (hopefully).

Use the already painstakingly found `workspaces` instead of naively using `folder_roots` from editor.

Co-authored-by: Emil Lauridsen <mine809@gmail.com>
This commit is contained in:
bors[bot] 2020-01-11 20:41:41 +00:00 committed by GitHub
commit 3924c7de50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 4 deletions

View File

@ -58,6 +58,12 @@ impl CheckWatcher {
CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle), shared }
}
/// Returns a CheckWatcher that doesn't actually do anything
pub fn dummy() -> CheckWatcher {
let shared = Arc::new(RwLock::new(CheckWatcherSharedState::new()));
CheckWatcher { task_recv: never(), cmd_send: None, handle: None, shared }
}
/// Schedule a re-start of the cargo check worker.
pub fn update(&self) {
if let Some(cmd_send) = &self.cmd_send {

View File

@ -132,8 +132,20 @@ impl WorldState {
change.set_crate_graph(crate_graph);
// FIXME: Figure out the multi-workspace situation
let check_watcher =
CheckWatcher::new(&options.cargo_watch, folder_roots.first().cloned().unwrap());
let check_watcher = workspaces
.iter()
.find_map(|w| match w {
ProjectWorkspace::Cargo { cargo, .. } => Some(cargo),
ProjectWorkspace::Json { .. } => None,
})
.map(|cargo| {
let cargo_project_root = cargo.workspace_root().to_path_buf();
CheckWatcher::new(&options.cargo_watch, cargo_project_root)
})
.unwrap_or_else(|| {
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
CheckWatcher::dummy()
});
let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags);
analysis_host.apply_change(change);

View File

@ -21,7 +21,7 @@ use crate::Result;
pub struct CargoWorkspace {
packages: Arena<Package, PackageData>,
targets: Arena<Target, TargetData>,
pub(crate) workspace_root: PathBuf,
workspace_root: PathBuf,
}
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
@ -225,4 +225,8 @@ impl CargoWorkspace {
pub fn target_by_root(&self, root: &Path) -> Option<Target> {
self.packages().filter_map(|pkg| pkg.targets(self).find(|it| it.root(self) == root)).next()
}
pub fn workspace_root(&self) -> &Path {
&self.workspace_root
}
}

View File

@ -333,7 +333,7 @@ impl ProjectWorkspace {
pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
match self {
ProjectWorkspace::Cargo { cargo, .. } => {
Some(cargo.workspace_root.as_ref()).filter(|root| path.starts_with(root))
Some(cargo.workspace_root()).filter(|root| path.starts_with(root))
}
ProjectWorkspace::Json { project: JsonProject { roots, .. } } => roots
.iter()