Merge pull request #18738 from Veykril/push-vqxqutskzvvu

fix: Properly check if workspace flychecking is allowed
This commit is contained in:
Lukas Wirth 2024-12-22 12:11:00 +00:00 committed by GitHub
commit 066284addd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 8 deletions

View file

@ -644,7 +644,8 @@ config_data! {
/// Aliased as `"checkOnSave.targets"`.
check_targets | checkOnSave_targets | checkOnSave_target: Option<CheckOnSaveTargets> = None,
/// Whether `--workspace` should be passed to `cargo check`.
/// If false, `-p <package>` will be passed instead.
/// If false, `-p <package>` 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.

View file

@ -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(())
}

View file

@ -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));
}

View file

@ -270,7 +270,8 @@ Aliased as `"checkOnSave.targets"`.
+
--
Whether `--workspace` should be passed to `cargo check`.
If false, `-p <package>` will be passed instead.
If false, `-p <package>` 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`)::
+

View file

@ -1098,7 +1098,7 @@
"title": "check",
"properties": {
"rust-analyzer.check.workspace": {
"markdownDescription": "Whether `--workspace` should be passed to `cargo check`.\nIf false, `-p <package>` will be passed instead.",
"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.",
"default": true,
"type": "boolean"
}