@@ -15,6 +15,7 @@ use vfs::{AbsPathBuf, ChangeKind, VfsPath};
1515
1616use crate :: {
1717 config:: { Config , ConfigChange } ,
18+ flycheck:: Target ,
1819 global_state:: { FetchWorkspaceRequest , GlobalState } ,
1920 lsp:: { from_proto, utils:: apply_document_changes} ,
2021 lsp_ext:: { self , RunFlycheckParams } ,
@@ -186,7 +187,7 @@ pub(crate) fn handle_did_save_text_document(
186187 } else if state. config . check_on_save ( ) {
187188 // No specific flycheck was triggered, so let's trigger all of them.
188189 for flycheck in state. flycheck . iter ( ) {
189- flycheck. restart_workspace ( None , None ) ;
190+ flycheck. restart_workspace ( None ) ;
190191 }
191192 }
192193 Ok ( ( ) )
@@ -289,18 +290,25 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
289290 let mut updated = false ;
290291 let task = move || -> std:: result:: Result < ( ) , ide:: Cancelled > {
291292 // 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+ } ;
299307
300- None
308+ Some ( tgt )
301309 } ) ;
302310
303- let crate_ids = if target_is_bin . is_some ( ) {
311+ let crate_ids = if target . is_some ( ) {
304312 // Trigger flychecks for the only workspace which the binary crate belongs to
305313 world. analysis . crates_for ( file_id) ?. into_iter ( ) . unique ( ) . collect :: < Vec < _ > > ( )
306314 } else {
@@ -364,12 +372,11 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
364372 for ( id, package) in workspace_ids. clone ( ) {
365373 if id == flycheck. id ( ) {
366374 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 ( ) ) ,
373380 }
374381 continue ;
375382 }
@@ -378,7 +385,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
378385 // No specific flycheck was triggered, so let's trigger all of them.
379386 if !updated {
380387 for flycheck in world. flycheck . iter ( ) {
381- flycheck. restart_workspace ( saved_file. clone ( ) , None ) ;
388+ flycheck. restart_workspace ( saved_file. clone ( ) ) ;
382389 }
383390 }
384391 Ok ( ( ) )
@@ -420,7 +427,7 @@ pub(crate) fn handle_run_flycheck(
420427 }
421428 // No specific flycheck was triggered, so let's trigger all of them.
422429 for flycheck in state. flycheck . iter ( ) {
423- flycheck. restart_workspace ( None , None ) ;
430+ flycheck. restart_workspace ( None ) ;
424431 }
425432 Ok ( ( ) )
426433}
0 commit comments