Skip to content

Commit

Permalink
Merge pull request #18738 from Veykril/push-vqxqutskzvvu
Browse files Browse the repository at this point in the history
fix: Properly check if workspace flychecking is allowed
  • Loading branch information
Veykril authored Dec 22, 2024
2 parents 84b7c8b + b08d1f9 commit c38d297
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
3 changes: 2 additions & 1 deletion src/tools/rust-analyzer/docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`)::
+
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit c38d297

Please sign in to comment.