@@ -10,6 +10,7 @@ use lsp_types::{
1010 DidOpenTextDocumentParams , DidSaveTextDocumentParams , WorkDoneProgressCancelParams ,
1111} ;
1212use paths:: Utf8PathBuf ;
13+ use stdx:: TupleExt ;
1314use triomphe:: Arc ;
1415use vfs:: { AbsPathBuf , ChangeKind , VfsPath } ;
1516
@@ -290,11 +291,11 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
290291 let mut updated = false ;
291292 let task = move || -> std:: result:: Result < ( ) , ide:: Cancelled > {
292293 // Is the target binary? If so we let flycheck run only for the workspace that contains the crate.
293- let target = TargetSpec :: for_file ( & world, file_id) ?. and_then ( |x | {
294- let tgt_kind = x . target_kind ( ) ;
295- let tgt_name = match x {
296- TargetSpec :: Cargo ( c) => c. target ,
297- TargetSpec :: ProjectJson ( p) => p. label ,
294+ let target = TargetSpec :: for_file ( & world, file_id) ?. and_then ( |it | {
295+ let tgt_kind = it . target_kind ( ) ;
296+ let ( tgt_name, crate_id ) = match it {
297+ TargetSpec :: Cargo ( c) => ( c. target , c . crate_id ) ,
298+ TargetSpec :: ProjectJson ( p) => ( p. label , p . crate_id ) ,
298299 } ;
299300
300301 let tgt = match tgt_kind {
@@ -305,25 +306,25 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
305306 _ => return None ,
306307 } ;
307308
308- Some ( tgt)
309+ Some ( ( tgt, crate_id ) )
309310 } ) ;
310311
311- let crate_ids = if target. is_some ( ) {
312- // Trigger flychecks for the only workspace which the binary crate belongs to
313- world. analysis . crates_for ( file_id) ?. into_iter ( ) . unique ( ) . collect :: < Vec < _ > > ( )
314- } else {
315- // Trigger flychecks for all workspaces that depend on the saved file
316- // Crates containing or depending on the saved file
317- world
318- . analysis
319- . crates_for ( file_id) ?
320- . into_iter ( )
321- . flat_map ( |id| world. analysis . transitive_rev_deps ( id) )
322- . flatten ( )
323- . unique ( )
324- . collect :: < Vec < _ > > ( )
312+ let crate_ids = match target {
313+ // Trigger flychecks for the only crate which the target belongs to
314+ Some ( ( _, krate) ) => vec ! [ krate] ,
315+ None => {
316+ // Trigger flychecks for all workspaces that depend on the saved file
317+ // Crates containing or depending on the saved file
318+ world
319+ . analysis
320+ . crates_for ( file_id) ?
321+ . into_iter ( )
322+ . flat_map ( |id| world. analysis . transitive_rev_deps ( id) )
323+ . flatten ( )
324+ . unique ( )
325+ . collect :: < Vec < _ > > ( )
326+ }
325327 } ;
326-
327328 let crate_root_paths: Vec < _ > = crate_ids
328329 . iter ( )
329330 . filter_map ( |& crate_id| {
@@ -375,7 +376,8 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
375376 match package
376377 . filter ( |_| !world. config . flycheck_workspace ( ) || target. is_some ( ) )
377378 {
378- Some ( package) => flycheck. restart_for_package ( package, target. clone ( ) ) ,
379+ Some ( package) => flycheck
380+ . restart_for_package ( package, target. clone ( ) . map ( TupleExt :: head) ) ,
379381 None => flycheck. restart_workspace ( saved_file. clone ( ) ) ,
380382 }
381383 continue ;
0 commit comments