diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 40fd294e72..b06117f738 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -644,7 +644,8 @@ config_data! { /// Aliased as `"checkOnSave.targets"`. check_targets | checkOnSave_targets | checkOnSave_target: Option = None, /// Whether `--workspace` should be passed to `cargo check`. - /// If false, `-p ` will be passed instead. + /// If false, `-p ` will be passed instead if applicable. In case it is not, no + /// check will be performed. check_workspace: bool = true, /// These proc-macros will be ignored when trying to expand them. diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs index 5e7262b14c..83c425bd71 100644 --- a/crates/rust-analyzer/src/handlers/notification.rs +++ b/crates/rust-analyzer/src/handlers/notification.rs @@ -189,7 +189,7 @@ pub(crate) fn handle_did_save_text_document( if !state.config.check_on_save(Some(sr)) || run_flycheck(state, vfs_path) { return Ok(()); } - } else if state.config.check_on_save(None) { + } else if state.config.check_on_save(None) && state.config.flycheck_workspace(None) { // No specific flycheck was triggered, so let's trigger all of them. for flycheck in state.flycheck.iter() { flycheck.restart_workspace(None); @@ -294,6 +294,7 @@ fn run_flycheck(state: &mut GlobalState, vfs_path: VfsPath) -> bool { if let Some(file_id) = file_id { let world = state.snapshot(); let source_root_id = world.analysis.source_root_id(file_id).ok(); + let may_flycheck_workspace = state.config.flycheck_workspace(None); let mut updated = false; let task = move || -> std::result::Result<(), ide::Cancelled> { // 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 { } } // No specific flycheck was triggered, so let's trigger all of them. - if !updated { + if !updated && may_flycheck_workspace { for flycheck in world.flycheck.iter() { flycheck.restart_workspace(saved_file.clone()); } @@ -432,8 +433,10 @@ pub(crate) fn handle_run_flycheck( } } // No specific flycheck was triggered, so let's trigger all of them. - for flycheck in state.flycheck.iter() { - flycheck.restart_workspace(None); + if state.config.flycheck_workspace(None) { + for flycheck in state.flycheck.iter() { + flycheck.restart_workspace(None); + } } Ok(()) } diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 343910b52b..2101f6443e 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -408,7 +408,7 @@ impl GlobalState { if self.is_quiescent() { let became_quiescent = !was_quiescent; if became_quiescent { - if self.config.check_on_save(None) { + if self.config.check_on_save(None) && self.config.flycheck_workspace(None) { // Project has loaded properly, kick off initial flycheck self.flycheck.iter().for_each(|flycheck| flycheck.restart_workspace(None)); } diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 1195a85cf7..142aa22a70 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc @@ -270,7 +270,8 @@ Aliased as `"checkOnSave.targets"`. + -- Whether `--workspace` should be passed to `cargo check`. -If false, `-p ` will be passed instead. +If false, `-p ` will be passed instead if applicable. In case it is not, no +check will be performed. -- [[rust-analyzer.completion.addSemicolonToUnit]]rust-analyzer.completion.addSemicolonToUnit (default: `true`):: + diff --git a/editors/code/package.json b/editors/code/package.json index 469c1b458d..df97efaae7 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -1098,7 +1098,7 @@ "title": "check", "properties": { "rust-analyzer.check.workspace": { - "markdownDescription": "Whether `--workspace` should be passed to `cargo check`.\nIf false, `-p ` will be passed instead.", + "markdownDescription": "Whether `--workspace` should be passed to `cargo check`.\nIf false, `-p ` will be passed instead if applicable. In case it is not, no\ncheck will be performed.", "default": true, "type": "boolean" }