@@ -10,6 +10,7 @@ use lsp_types::{
10
10
DidOpenTextDocumentParams , DidSaveTextDocumentParams , WorkDoneProgressCancelParams ,
11
11
} ;
12
12
use paths:: Utf8PathBuf ;
13
+ use stdx:: TupleExt ;
13
14
use triomphe:: Arc ;
14
15
use vfs:: { AbsPathBuf , ChangeKind , VfsPath } ;
15
16
@@ -290,11 +291,11 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
290
291
let mut updated = false ;
291
292
let task = move || -> std:: result:: Result < ( ) , ide:: Cancelled > {
292
293
// 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 ) ,
298
299
} ;
299
300
300
301
let tgt = match tgt_kind {
@@ -305,25 +306,25 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
305
306
_ => return None ,
306
307
} ;
307
308
308
- Some ( tgt)
309
+ Some ( ( tgt, crate_id ) )
309
310
} ) ;
310
311
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
+ }
325
327
} ;
326
-
327
328
let crate_root_paths: Vec < _ > = crate_ids
328
329
. iter ( )
329
330
. filter_map ( |& crate_id| {
@@ -375,7 +376,8 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
375
376
match package
376
377
. filter ( |_| !world. config . flycheck_workspace ( ) || target. is_some ( ) )
377
378
{
378
- Some ( package) => flycheck. restart_for_package ( package, target. clone ( ) ) ,
379
+ Some ( package) => flycheck
380
+ . restart_for_package ( package, target. clone ( ) . map ( TupleExt :: head) ) ,
379
381
None => flycheck. restart_workspace ( saved_file. clone ( ) ) ,
380
382
}
381
383
continue ;
0 commit comments