mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Merge #2791
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:
commit
3924c7de50
@ -58,6 +58,12 @@ impl CheckWatcher {
|
|||||||
CheckWatcher { task_recv, cmd_send: Some(cmd_send), handle: Some(handle), shared }
|
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.
|
/// Schedule a re-start of the cargo check worker.
|
||||||
pub fn update(&self) {
|
pub fn update(&self) {
|
||||||
if let Some(cmd_send) = &self.cmd_send {
|
if let Some(cmd_send) = &self.cmd_send {
|
||||||
|
@ -132,8 +132,20 @@ impl WorldState {
|
|||||||
change.set_crate_graph(crate_graph);
|
change.set_crate_graph(crate_graph);
|
||||||
|
|
||||||
// FIXME: Figure out the multi-workspace situation
|
// FIXME: Figure out the multi-workspace situation
|
||||||
let check_watcher =
|
let check_watcher = workspaces
|
||||||
CheckWatcher::new(&options.cargo_watch, folder_roots.first().cloned().unwrap());
|
.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);
|
let mut analysis_host = AnalysisHost::new(lru_capacity, feature_flags);
|
||||||
analysis_host.apply_change(change);
|
analysis_host.apply_change(change);
|
||||||
|
@ -21,7 +21,7 @@ use crate::Result;
|
|||||||
pub struct CargoWorkspace {
|
pub struct CargoWorkspace {
|
||||||
packages: Arena<Package, PackageData>,
|
packages: Arena<Package, PackageData>,
|
||||||
targets: Arena<Target, TargetData>,
|
targets: Arena<Target, TargetData>,
|
||||||
pub(crate) workspace_root: PathBuf,
|
workspace_root: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
|
||||||
@ -225,4 +225,8 @@ impl CargoWorkspace {
|
|||||||
pub fn target_by_root(&self, root: &Path) -> Option<Target> {
|
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()
|
self.packages().filter_map(|pkg| pkg.targets(self).find(|it| it.root(self) == root)).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn workspace_root(&self) -> &Path {
|
||||||
|
&self.workspace_root
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ impl ProjectWorkspace {
|
|||||||
pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
|
pub fn workspace_root_for(&self, path: &Path) -> Option<&Path> {
|
||||||
match self {
|
match self {
|
||||||
ProjectWorkspace::Cargo { cargo, .. } => {
|
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
|
ProjectWorkspace::Json { project: JsonProject { roots, .. } } => roots
|
||||||
.iter()
|
.iter()
|
||||||
|
Loading…
Reference in New Issue
Block a user