@@ -291,9 +291,15 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
291
291
let file_id = state. vfs . read ( ) . 0 . file_id ( & vfs_path) ;
292
292
if let Some ( file_id) = file_id {
293
293
let world = state. snapshot ( ) ;
294
+ let invocation_strategy_once = state. config . flycheck ( None ) . invocation_strategy_once ( ) ;
294
295
let may_flycheck_workspace = state. config . flycheck_workspace ( None ) ;
295
296
let mut updated = false ;
296
297
let task = move || -> std:: result:: Result < ( ) , ide:: Cancelled > {
298
+ if invocation_strategy_once {
299
+ let saved_file = vfs_path. as_path ( ) . map ( |p| p. to_owned ( ) ) ;
300
+ world. flycheck [ 0 ] . restart_workspace ( saved_file. clone ( ) ) ;
301
+ }
302
+
297
303
let target = TargetSpec :: for_file ( & world, file_id) ?. and_then ( |it| {
298
304
let tgt_kind = it. target_kind ( ) ;
299
305
let ( tgt_name, root, package) = match it {
@@ -320,16 +326,15 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
320
326
// the user opted into package checks then
321
327
let package_check_allowed = target. is_some ( ) || !may_flycheck_workspace;
322
328
if package_check_allowed {
323
- let workspace =
324
- world. workspaces . iter ( ) . enumerate ( ) . find ( |( _, ws) | match & ws. kind {
325
- project_model:: ProjectWorkspaceKind :: Cargo { cargo, .. }
326
- | project_model:: ProjectWorkspaceKind :: DetachedFile {
327
- cargo : Some ( ( cargo, _, _) ) ,
328
- ..
329
- } => * cargo. workspace_root ( ) == root,
330
- _ => false ,
331
- } ) ;
332
- if let Some ( ( idx, _) ) = workspace {
329
+ let workspace = world. workspaces . iter ( ) . position ( |ws| match & ws. kind {
330
+ project_model:: ProjectWorkspaceKind :: Cargo { cargo, .. }
331
+ | project_model:: ProjectWorkspaceKind :: DetachedFile {
332
+ cargo : Some ( ( cargo, _, _) ) ,
333
+ ..
334
+ } => * cargo. workspace_root ( ) == root,
335
+ _ => false ,
336
+ } ) ;
337
+ if let Some ( idx) = workspace {
333
338
world. flycheck [ idx] . restart_for_package ( package, target) ;
334
339
}
335
340
}
0 commit comments