@@ -303,11 +303,11 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
303
303
let world = state. snapshot ( ) ;
304
304
let invocation_strategy_once = state. config . flycheck ( None ) . invocation_strategy_once ( ) ;
305
305
let may_flycheck_workspace = state. config . flycheck_workspace ( None ) ;
306
- let mut updated = false ;
306
+ let mut workspace_check_triggered = false ;
307
307
let task = move || -> std:: result:: Result < ( ) , Cancelled > {
308
+ let saved_file = vfs_path. as_path ( ) . map ( |p| p. to_owned ( ) ) ;
308
309
if invocation_strategy_once {
309
- let saved_file = vfs_path. as_path ( ) . map ( |p| p. to_owned ( ) ) ;
310
- world. flycheck [ 0 ] . restart_workspace ( saved_file) ;
310
+ world. flycheck [ 0 ] . restart_workspace ( saved_file. clone ( ) ) ;
311
311
}
312
312
313
313
let target = TargetSpec :: for_file ( & world, file_id) ?. and_then ( |it| {
@@ -330,6 +330,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
330
330
tracing:: debug!( ?target, "flycheck target" ) ;
331
331
// we have a specific non-library target, attempt to only check that target, nothing
332
332
// else will be affected
333
+ let mut package_workspace_idx = None ;
333
334
if let Some ( ( target, root, package) ) = target {
334
335
// trigger a package check if we have a non-library target as that can't affect
335
336
// anything else in the workspace OR if we're not allowed to check the workspace as
@@ -345,6 +346,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
345
346
_ => false ,
346
347
} ) ;
347
348
if let Some ( idx) = workspace {
349
+ package_workspace_idx = Some ( idx) ;
348
350
world. flycheck [ idx] . restart_for_package ( package, target) ;
349
351
}
350
352
}
@@ -381,8 +383,15 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
381
383
tracing:: debug!( ?crate_root_paths, "flycheck crate roots" ) ;
382
384
383
385
// Find all workspaces that have at least one target containing the saved file
384
- let workspace_ids =
385
- world. workspaces . iter ( ) . enumerate ( ) . filter ( |( _, ws) | match & ws. kind {
386
+ let workspace_ids = world
387
+ . workspaces
388
+ . iter ( )
389
+ . enumerate ( )
390
+ . filter ( |& ( idx, _) | match package_workspace_idx {
391
+ Some ( pkg_idx) => idx != pkg_idx,
392
+ None => true ,
393
+ } )
394
+ . filter ( |& ( _, ws) | match & ws. kind {
386
395
project_model:: ProjectWorkspaceKind :: Cargo { cargo, .. }
387
396
| project_model:: ProjectWorkspaceKind :: DetachedFile {
388
397
cargo : Some ( ( cargo, _, _) ) ,
@@ -399,20 +408,18 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
399
408
project_model:: ProjectWorkspaceKind :: DetachedFile { .. } => false ,
400
409
} ) ;
401
410
402
- let saved_file = vfs_path. as_path ( ) . map ( |p| p. to_owned ( ) ) ;
403
-
404
411
// Find and trigger corresponding flychecks
405
412
' flychecks: for flycheck in world. flycheck . iter ( ) {
406
413
for ( id, _) in workspace_ids. clone ( ) {
407
414
if id == flycheck. id ( ) {
408
- updated = true ;
415
+ workspace_check_triggered = true ;
409
416
flycheck. restart_workspace ( saved_file. clone ( ) ) ;
410
417
continue ' flychecks;
411
418
}
412
419
}
413
420
}
414
421
// No specific flycheck was triggered, so let's trigger all of them.
415
- if !updated {
422
+ if !workspace_check_triggered && package_workspace_idx . is_none ( ) {
416
423
for flycheck in world. flycheck . iter ( ) {
417
424
flycheck. restart_workspace ( saved_file. clone ( ) ) ;
418
425
}
0 commit comments