@@ -9,7 +9,8 @@ use std::{
9
9
10
10
use always_assert:: always;
11
11
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 ;
13
14
use lsp_server:: { Connection , Notification , Request } ;
14
15
use lsp_types:: notification:: Notification as _;
15
16
use vfs:: { ChangeKind , FileId } ;
@@ -727,9 +728,21 @@ impl GlobalState {
727
728
let ( vfs, _) = & * this. vfs . read ( ) ;
728
729
if let Some ( file_id) = vfs. file_id ( & vfs_path) {
729
730
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 ( ) ;
731
744
732
- let paths : Vec < _ > = crate_ids
745
+ let crate_root_paths : Vec < _ > = crate_ids
733
746
. iter ( )
734
747
. filter_map ( |& crate_id| {
735
748
analysis
@@ -740,23 +753,26 @@ impl GlobalState {
740
753
. transpose ( )
741
754
} )
742
755
. 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 ( ) ;
744
758
759
+ // Find all workspaces that have at least one target containing the saved file
745
760
let workspace_ids =
746
761
this. workspaces . iter ( ) . enumerate ( ) . filter ( |( _, ws) | match ws {
747
762
project_model:: ProjectWorkspace :: Cargo { cargo, .. } => {
748
763
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
+ } )
753
767
} )
754
768
}
755
769
project_model:: ProjectWorkspace :: Json { project, .. } => project
756
770
. crates ( )
757
771
. any ( |( c, _) | crate_ids. iter ( ) . any ( |& crate_id| crate_id == c) ) ,
758
772
project_model:: ProjectWorkspace :: DetachedFiles { .. } => false ,
759
773
} ) ;
774
+
775
+ // Find and trigger corresponding flychecks
760
776
for flycheck in & this. flycheck {
761
777
for ( id, _) in workspace_ids. clone ( ) {
762
778
if id == flycheck. id ( ) {
0 commit comments