Unnamed repository; edit this file 'description' to name the repository.
Make manual flycheck runs work when checkOnSave is disabled
Lukas Wirth 2022-12-18
parent e0aa5af · commit cdfe98f
-rw-r--r--crates/rust-analyzer/src/config.rs14
-rw-r--r--crates/rust-analyzer/src/main_loop.rs21
-rw-r--r--crates/rust-analyzer/src/reload.rs10
3 files changed, 17 insertions, 28 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 6c0d712a4f..835b37c98e 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -1125,11 +1125,8 @@ impl Config {
}
}
- pub fn flycheck(&self) -> Option<FlycheckConfig> {
- if !self.data.checkOnSave_enable {
- return None;
- }
- let flycheck_config = match &self.data.checkOnSave_overrideCommand {
+ pub fn flycheck(&self) -> FlycheckConfig {
+ match &self.data.checkOnSave_overrideCommand {
Some(args) if !args.is_empty() => {
let mut args = args.clone();
let command = args.remove(0);
@@ -1183,8 +1180,11 @@ impl Config {
extra_args: self.data.checkOnSave_extraArgs.clone(),
extra_env: self.check_on_save_extra_env(),
},
- };
- Some(flycheck_config)
+ }
+ }
+
+ pub fn check_on_save(&self) -> bool {
+ self.data.checkOnSave_enable
}
pub fn runnables(&self) -> RunnablesConfig {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index d979317b21..8d621cc36a 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -581,10 +581,7 @@ impl GlobalState {
// When we're running multiple flychecks, we have to include a disambiguator in
// the title, or the editor complains. Note that this is a user-facing string.
let title = if self.flycheck.len() == 1 {
- match self.config.flycheck() {
- Some(config) => format!("{}", config),
- None => "cargo check".to_string(),
- }
+ format!("{}", self.config.flycheck())
} else {
format!("cargo check (#{})", id + 1)
};
@@ -593,7 +590,7 @@ impl GlobalState {
state,
message,
None,
- Some(format!("rust-analyzer/checkOnSave/{}", id)),
+ Some(format!("rust-analyzer/flycheck/{}", id)),
);
}
}
@@ -796,7 +793,7 @@ impl GlobalState {
})?
.on::<lsp_types::notification::WorkDoneProgressCancel>(|this, params| {
if let lsp_types::NumberOrString::String(s) = &params.token {
- if let Some(id) = s.strip_prefix("rust-analyzer/checkOnSave/") {
+ if let Some(id) = s.strip_prefix("rust-analyzer/flycheck/") {
if let Ok(id) = u32::from_str_radix(id, 10) {
if let Some(flycheck) = this.flycheck.get(id as usize) {
flycheck.cancel();
@@ -888,14 +885,14 @@ impl GlobalState {
}
}
- if run_flycheck(this, vfs_path) {
+ if !this.config.check_on_save() || run_flycheck(this, vfs_path) {
return Ok(());
}
- }
-
- // No specific flycheck was triggered, so let's trigger all of them.
- for flycheck in this.flycheck.iter() {
- flycheck.restart();
+ } else if this.config.check_on_save() {
+ // No specific flycheck was triggered, so let's trigger all of them.
+ for flycheck in this.flycheck.iter() {
+ flycheck.restart();
+ }
}
Ok(())
})?
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 748a189c20..3e7664d7d3 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -449,15 +449,7 @@ impl GlobalState {
fn reload_flycheck(&mut self) {
let _p = profile::span("GlobalState::reload_flycheck");
- let config = match self.config.flycheck() {
- Some(it) => it,
- None => {
- self.flycheck = Arc::new([]);
- self.diagnostics.clear_check_all();
- return;
- }
- };
-
+ let config = self.config.flycheck();
let sender = self.flycheck_sender.clone();
let invocation_strategy = match config {
FlycheckConfig::CargoCommand { .. } => flycheck::InvocationStrategy::PerWorkspace,