@@ -15,6 +15,7 @@ use vfs::{AbsPathBuf, ChangeKind, VfsPath};
15
15
16
16
use crate :: {
17
17
config:: { Config , ConfigChange } ,
18
+ flycheck:: Target ,
18
19
global_state:: { FetchWorkspaceRequest , GlobalState } ,
19
20
lsp:: { from_proto, utils:: apply_document_changes} ,
20
21
lsp_ext:: { self , RunFlycheckParams } ,
@@ -186,7 +187,7 @@ pub(crate) fn handle_did_save_text_document(
186
187
} else if state. config . check_on_save ( ) {
187
188
// No specific flycheck was triggered, so let's trigger all of them.
188
189
for flycheck in state. flycheck . iter ( ) {
189
- flycheck. restart_workspace ( None , None ) ;
190
+ flycheck. restart_workspace ( None ) ;
190
191
}
191
192
}
192
193
Ok ( ( ) )
@@ -289,18 +290,25 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
289
290
let mut updated = false ;
290
291
let task = move || -> std:: result:: Result < ( ) , ide:: Cancelled > {
291
292
// Is the target binary? If so we let flycheck run only for the workspace that contains the crate.
292
- let target_is_bin = TargetSpec :: for_file ( & world, file_id) ?. and_then ( |x| {
293
- if x. target_kind ( ) == project_model:: TargetKind :: Bin {
294
- return match x {
295
- TargetSpec :: Cargo ( c) => Some ( c. target ) ,
296
- TargetSpec :: ProjectJson ( p) => Some ( p. label ) ,
297
- } ;
298
- }
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 ,
298
+ } ;
299
+
300
+ let tgt = match tgt_kind {
301
+ project_model:: TargetKind :: Bin => Target :: Bin ( tgt_name) ,
302
+ project_model:: TargetKind :: Example => Target :: Example ( tgt_name) ,
303
+ project_model:: TargetKind :: Test => Target :: Test ( tgt_name) ,
304
+ project_model:: TargetKind :: Bench => Target :: Benchmark ( tgt_name) ,
305
+ _ => return None ,
306
+ } ;
299
307
300
- None
308
+ Some ( tgt )
301
309
} ) ;
302
310
303
- let crate_ids = if target_is_bin . is_some ( ) {
311
+ let crate_ids = if target . is_some ( ) {
304
312
// Trigger flychecks for the only workspace which the binary crate belongs to
305
313
world. analysis . crates_for ( file_id) ?. into_iter ( ) . unique ( ) . collect :: < Vec < _ > > ( )
306
314
} else {
@@ -364,12 +372,11 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
364
372
for ( id, package) in workspace_ids. clone ( ) {
365
373
if id == flycheck. id ( ) {
366
374
updated = true ;
367
- match package. filter ( |_| !world. config . flycheck_workspace ( ) ) {
368
- Some ( package) => {
369
- flycheck. restart_for_package ( package, target_is_bin. clone ( ) )
370
- }
371
- None => flycheck
372
- . restart_workspace ( saved_file. clone ( ) , target_is_bin. clone ( ) ) ,
375
+ match package
376
+ . filter ( |_| !world. config . flycheck_workspace ( ) || target. is_some ( ) )
377
+ {
378
+ Some ( package) => flycheck. restart_for_package ( package, target. clone ( ) ) ,
379
+ None => flycheck. restart_workspace ( saved_file. clone ( ) ) ,
373
380
}
374
381
continue ;
375
382
}
@@ -378,7 +385,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
378
385
// No specific flycheck was triggered, so let's trigger all of them.
379
386
if !updated {
380
387
for flycheck in world. flycheck . iter ( ) {
381
- flycheck. restart_workspace ( saved_file. clone ( ) , None ) ;
388
+ flycheck. restart_workspace ( saved_file. clone ( ) ) ;
382
389
}
383
390
}
384
391
Ok ( ( ) )
@@ -420,7 +427,7 @@ pub(crate) fn handle_run_flycheck(
420
427
}
421
428
// No specific flycheck was triggered, so let's trigger all of them.
422
429
for flycheck in state. flycheck . iter ( ) {
423
- flycheck. restart_workspace ( None , None ) ;
430
+ flycheck. restart_workspace ( None ) ;
424
431
}
425
432
Ok ( ( ) )
426
433
}
0 commit comments