Skip to content

Commit b394f5d

Browse files
committed
Skip flycheck for workspace if it is already being checked
1 parent 9edc9cb commit b394f5d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
303303
let world = state.snapshot();
304304
let invocation_strategy_once = state.config.flycheck(None).invocation_strategy_once();
305305
let may_flycheck_workspace = state.config.flycheck_workspace(None);
306-
let mut updated = false;
306+
let mut workspace_check_triggered = false;
307307
let task = move || -> std::result::Result<(), Cancelled> {
308+
let saved_file = vfs_path.as_path().map(|p| p.to_owned());
308309
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());
311311
}
312312

313313
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 {
330330
tracing::debug!(?target, "flycheck target");
331331
// we have a specific non-library target, attempt to only check that target, nothing
332332
// else will be affected
333+
let mut package_workspace_idx = None;
333334
if let Some((target, root, package)) = target {
334335
// trigger a package check if we have a non-library target as that can't affect
335336
// 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 {
345346
_ => false,
346347
});
347348
if let Some(idx) = workspace {
349+
package_workspace_idx = Some(idx);
348350
world.flycheck[idx].restart_for_package(package, target);
349351
}
350352
}
@@ -381,8 +383,15 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
381383
tracing::debug!(?crate_root_paths, "flycheck crate roots");
382384

383385
// 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 {
386395
project_model::ProjectWorkspaceKind::Cargo { cargo, .. }
387396
| project_model::ProjectWorkspaceKind::DetachedFile {
388397
cargo: Some((cargo, _, _)),
@@ -399,20 +408,18 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
399408
project_model::ProjectWorkspaceKind::DetachedFile { .. } => false,
400409
});
401410

402-
let saved_file = vfs_path.as_path().map(|p| p.to_owned());
403-
404411
// Find and trigger corresponding flychecks
405412
'flychecks: for flycheck in world.flycheck.iter() {
406413
for (id, _) in workspace_ids.clone() {
407414
if id == flycheck.id() {
408-
updated = true;
415+
workspace_check_triggered = true;
409416
flycheck.restart_workspace(saved_file.clone());
410417
continue 'flychecks;
411418
}
412419
}
413420
}
414421
// 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() {
416423
for flycheck in world.flycheck.iter() {
417424
flycheck.restart_workspace(saved_file.clone());
418425
}

0 commit comments

Comments
 (0)