Skip to content

Commit df9d3db

Browse files
committed
Trigger flycheck on all transitive dependencies as well
1 parent d73b0d5 commit df9d3db

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use std::{
99

1010
use always_assert::always;
1111
use crossbeam_channel::{select, Receiver};
12-
use ide_db::base_db::{SourceDatabaseExt, VfsPath};
12+
use ide_db::base_db::{SourceDatabase, SourceDatabaseExt, VfsPath};
13+
use itertools::Itertools;
1314
use lsp_server::{Connection, Notification, Request};
1415
use lsp_types::notification::Notification as _;
1516
use vfs::{ChangeKind, FileId};
@@ -727,9 +728,21 @@ impl GlobalState {
727728
let (vfs, _) = &*this.vfs.read();
728729
if let Some(file_id) = vfs.file_id(&vfs_path) {
729730
let analysis = this.analysis_host.analysis();
730-
let crate_ids = analysis.crate_for(file_id)?;
731+
// Crates containing or depending on the saved file
732+
let crate_ids: Vec<_> = analysis
733+
.crate_for(file_id)?
734+
.into_iter()
735+
.flat_map(|id| {
736+
this.analysis_host
737+
.raw_database()
738+
.crate_graph()
739+
.transitive_rev_deps(id)
740+
})
741+
.sorted()
742+
.unique()
743+
.collect();
731744

732-
let paths: Vec<_> = crate_ids
745+
let crate_root_paths: Vec<_> = crate_ids
733746
.iter()
734747
.filter_map(|&crate_id| {
735748
analysis
@@ -740,23 +753,26 @@ impl GlobalState {
740753
.transpose()
741754
})
742755
.collect::<ide::Cancellable<_>>()?;
743-
let paths: Vec<_> = paths.iter().map(Deref::deref).collect();
756+
let crate_root_paths: Vec<_> =
757+
crate_root_paths.iter().map(Deref::deref).collect();
744758

759+
// Find all workspaces that have at least one target containing the saved file
745760
let workspace_ids =
746761
this.workspaces.iter().enumerate().filter(|(_, ws)| match ws {
747762
project_model::ProjectWorkspace::Cargo { cargo, .. } => {
748763
cargo.packages().any(|pkg| {
749-
cargo[pkg]
750-
.targets
751-
.iter()
752-
.any(|&it| paths.contains(&cargo[it].root.as_path()))
764+
cargo[pkg].targets.iter().any(|&it| {
765+
crate_root_paths.contains(&cargo[it].root.as_path())
766+
})
753767
})
754768
}
755769
project_model::ProjectWorkspace::Json { project, .. } => project
756770
.crates()
757771
.any(|(c, _)| crate_ids.iter().any(|&crate_id| crate_id == c)),
758772
project_model::ProjectWorkspace::DetachedFiles { .. } => false,
759773
});
774+
775+
// Find and trigger corresponding flychecks
760776
for flycheck in &this.flycheck {
761777
for (id, _) in workspace_ids.clone() {
762778
if id == flycheck.id() {

0 commit comments

Comments
 (0)