Skip to content

Commit cdfe98f

Browse files
committed
Make manual flycheck runs work when checkOnSave is disabled
1 parent e0aa5af commit cdfe98f

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,11 +1125,8 @@ impl Config {
11251125
}
11261126
}
11271127

1128-
pub fn flycheck(&self) -> Option<FlycheckConfig> {
1129-
if !self.data.checkOnSave_enable {
1130-
return None;
1131-
}
1132-
let flycheck_config = match &self.data.checkOnSave_overrideCommand {
1128+
pub fn flycheck(&self) -> FlycheckConfig {
1129+
match &self.data.checkOnSave_overrideCommand {
11331130
Some(args) if !args.is_empty() => {
11341131
let mut args = args.clone();
11351132
let command = args.remove(0);
@@ -1183,8 +1180,11 @@ impl Config {
11831180
extra_args: self.data.checkOnSave_extraArgs.clone(),
11841181
extra_env: self.check_on_save_extra_env(),
11851182
},
1186-
};
1187-
Some(flycheck_config)
1183+
}
1184+
}
1185+
1186+
pub fn check_on_save(&self) -> bool {
1187+
self.data.checkOnSave_enable
11881188
}
11891189

11901190
pub fn runnables(&self) -> RunnablesConfig {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,7 @@ impl GlobalState {
581581
// When we're running multiple flychecks, we have to include a disambiguator in
582582
// the title, or the editor complains. Note that this is a user-facing string.
583583
let title = if self.flycheck.len() == 1 {
584-
match self.config.flycheck() {
585-
Some(config) => format!("{}", config),
586-
None => "cargo check".to_string(),
587-
}
584+
format!("{}", self.config.flycheck())
588585
} else {
589586
format!("cargo check (#{})", id + 1)
590587
};
@@ -593,7 +590,7 @@ impl GlobalState {
593590
state,
594591
message,
595592
None,
596-
Some(format!("rust-analyzer/checkOnSave/{}", id)),
593+
Some(format!("rust-analyzer/flycheck/{}", id)),
597594
);
598595
}
599596
}
@@ -796,7 +793,7 @@ impl GlobalState {
796793
})?
797794
.on::<lsp_types::notification::WorkDoneProgressCancel>(|this, params| {
798795
if let lsp_types::NumberOrString::String(s) = &params.token {
799-
if let Some(id) = s.strip_prefix("rust-analyzer/checkOnSave/") {
796+
if let Some(id) = s.strip_prefix("rust-analyzer/flycheck/") {
800797
if let Ok(id) = u32::from_str_radix(id, 10) {
801798
if let Some(flycheck) = this.flycheck.get(id as usize) {
802799
flycheck.cancel();
@@ -888,14 +885,14 @@ impl GlobalState {
888885
}
889886
}
890887

891-
if run_flycheck(this, vfs_path) {
888+
if !this.config.check_on_save() || run_flycheck(this, vfs_path) {
892889
return Ok(());
893890
}
894-
}
895-
896-
// No specific flycheck was triggered, so let's trigger all of them.
897-
for flycheck in this.flycheck.iter() {
898-
flycheck.restart();
891+
} else if this.config.check_on_save() {
892+
// No specific flycheck was triggered, so let's trigger all of them.
893+
for flycheck in this.flycheck.iter() {
894+
flycheck.restart();
895+
}
899896
}
900897
Ok(())
901898
})?

crates/rust-analyzer/src/reload.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,7 @@ impl GlobalState {
449449

450450
fn reload_flycheck(&mut self) {
451451
let _p = profile::span("GlobalState::reload_flycheck");
452-
let config = match self.config.flycheck() {
453-
Some(it) => it,
454-
None => {
455-
self.flycheck = Arc::new([]);
456-
self.diagnostics.clear_check_all();
457-
return;
458-
}
459-
};
460-
452+
let config = self.config.flycheck();
461453
let sender = self.flycheck_sender.clone();
462454
let invocation_strategy = match config {
463455
FlycheckConfig::CargoCommand { .. } => flycheck::InvocationStrategy::PerWorkspace,

0 commit comments

Comments
 (0)