Skip to content

Commit b912eac

Browse files
committed
fix: lookup flycheck by ID instead of vector index
After a recent introduction of per-package flycheck for JSON projects, the code assumed that `world.flycheck` indices matched `world.workspaces` indices. However, not all workspaces have flycheck enabled (e.g., JSON projects without a flycheck template configured), so the flycheck vector can be shorter than the workspaces vector. This caused an index-out-of-bounds panic when saving a file in a JSON project without flycheck configured: thread 'Worker' panicked at notification.rs: index out of bounds: the len is 0 but the index is 0 Fix by looking up the flycheck handle by its ID (which is the workspace index set during spawn) rather than using the workspace index directly as a vector index.
1 parent adbff8b commit b912eac

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,21 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
387387
} => false,
388388
});
389389
if let Some(idx) = package_workspace_idx {
390-
let workspace_deps =
391-
world.all_workspace_dependencies_for_package(&package);
392-
world.flycheck[idx].restart_for_package(
393-
package,
394-
target,
395-
workspace_deps,
396-
saved_file.clone(),
397-
);
390+
// flycheck handles are indexed by their ID (which is the workspace index),
391+
// but not all workspaces have flycheck enabled (e.g., JSON projects without
392+
// a flycheck template). Find the flycheck handle by its ID.
393+
if let Some(flycheck) =
394+
world.flycheck.iter().find(|fc| fc.id() == idx)
395+
{
396+
let workspace_deps =
397+
world.all_workspace_dependencies_for_package(&package);
398+
flycheck.restart_for_package(
399+
package,
400+
target,
401+
workspace_deps,
402+
saved_file.clone(),
403+
);
404+
}
398405
}
399406
}
400407
}

0 commit comments

Comments
 (0)