Skip to content

Commit b08d1f9

Browse files
committed
fix: Properly check if workspace flychecking is allowed
1 parent b694ff3 commit b08d1f9

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@ config_data! {
644644
/// Aliased as `"checkOnSave.targets"`.
645645
check_targets | checkOnSave_targets | checkOnSave_target: Option<CheckOnSaveTargets> = None,
646646
/// Whether `--workspace` should be passed to `cargo check`.
647-
/// If false, `-p <package>` will be passed instead.
647+
/// If false, `-p <package>` will be passed instead if applicable. In case it is not, no
648+
/// check will be performed.
648649
check_workspace: bool = true,
649650

650651
/// These proc-macros will be ignored when trying to expand them.

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub(crate) fn handle_did_save_text_document(
189189
if !state.config.check_on_save(Some(sr)) || run_flycheck(state, vfs_path) {
190190
return Ok(());
191191
}
192-
} else if state.config.check_on_save(None) {
192+
} else if state.config.check_on_save(None) && state.config.flycheck_workspace(None) {
193193
// No specific flycheck was triggered, so let's trigger all of them.
194194
for flycheck in state.flycheck.iter() {
195195
flycheck.restart_workspace(None);
@@ -294,6 +294,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
294294
if let Some(file_id) = file_id {
295295
let world = state.snapshot();
296296
let source_root_id = world.analysis.source_root_id(file_id).ok();
297+
let may_flycheck_workspace = state.config.flycheck_workspace(None);
297298
let mut updated = false;
298299
let task = move || -> std::result::Result<(), ide::Cancelled> {
299300
// Is the target binary? If so we let flycheck run only for the workspace that contains the crate.
@@ -389,7 +390,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool {
389390
}
390391
}
391392
// No specific flycheck was triggered, so let's trigger all of them.
392-
if !updated {
393+
if !updated && may_flycheck_workspace {
393394
for flycheck in world.flycheck.iter() {
394395
flycheck.restart_workspace(saved_file.clone());
395396
}
@@ -432,8 +433,10 @@ pub(crate) fn handle_run_flycheck(
432433
}
433434
}
434435
// No specific flycheck was triggered, so let's trigger all of them.
435-
for flycheck in state.flycheck.iter() {
436-
flycheck.restart_workspace(None);
436+
if state.config.flycheck_workspace(None) {
437+
for flycheck in state.flycheck.iter() {
438+
flycheck.restart_workspace(None);
439+
}
437440
}
438441
Ok(())
439442
}

src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl GlobalState {
408408
if self.is_quiescent() {
409409
let became_quiescent = !was_quiescent;
410410
if became_quiescent {
411-
if self.config.check_on_save(None) {
411+
if self.config.check_on_save(None) && self.config.flycheck_workspace(None) {
412412
// Project has loaded properly, kick off initial flycheck
413413
self.flycheck.iter().for_each(|flycheck| flycheck.restart_workspace(None));
414414
}

src/tools/rust-analyzer/docs/user/generated_config.adoc

+2-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ Aliased as `"checkOnSave.targets"`.
270270
+
271271
--
272272
Whether `--workspace` should be passed to `cargo check`.
273-
If false, `-p <package>` will be passed instead.
273+
If false, `-p <package>` will be passed instead if applicable. In case it is not, no
274+
check will be performed.
274275
--
275276
[[rust-analyzer.completion.addSemicolonToUnit]]rust-analyzer.completion.addSemicolonToUnit (default: `true`)::
276277
+

src/tools/rust-analyzer/editors/code/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@
10981098
"title": "check",
10991099
"properties": {
11001100
"rust-analyzer.check.workspace": {
1101-
"markdownDescription": "Whether `--workspace` should be passed to `cargo check`.\nIf false, `-p <package>` will be passed instead.",
1101+
"markdownDescription": "Whether `--workspace` should be passed to `cargo check`.\nIf false, `-p <package>` will be passed instead if applicable. In case it is not, no\ncheck will be performed.",
11021102
"default": true,
11031103
"type": "boolean"
11041104
}

0 commit comments

Comments
 (0)