mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Make manual flycheck runs work when checkOnSave is disabled
This commit is contained in:
parent
e0aa5afd7b
commit
cdfe98fe94
3 changed files with 17 additions and 28 deletions
|
@ -1125,11 +1125,8 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flycheck(&self) -> Option<FlycheckConfig> {
|
pub fn flycheck(&self) -> FlycheckConfig {
|
||||||
if !self.data.checkOnSave_enable {
|
match &self.data.checkOnSave_overrideCommand {
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let flycheck_config = match &self.data.checkOnSave_overrideCommand {
|
|
||||||
Some(args) if !args.is_empty() => {
|
Some(args) if !args.is_empty() => {
|
||||||
let mut args = args.clone();
|
let mut args = args.clone();
|
||||||
let command = args.remove(0);
|
let command = args.remove(0);
|
||||||
|
@ -1183,8 +1180,11 @@ impl Config {
|
||||||
extra_args: self.data.checkOnSave_extraArgs.clone(),
|
extra_args: self.data.checkOnSave_extraArgs.clone(),
|
||||||
extra_env: self.check_on_save_extra_env(),
|
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 {
|
pub fn runnables(&self) -> RunnablesConfig {
|
||||||
|
|
|
@ -581,10 +581,7 @@ impl GlobalState {
|
||||||
// When we're running multiple flychecks, we have to include a disambiguator in
|
// 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.
|
// the title, or the editor complains. Note that this is a user-facing string.
|
||||||
let title = if self.flycheck.len() == 1 {
|
let title = if self.flycheck.len() == 1 {
|
||||||
match self.config.flycheck() {
|
format!("{}", self.config.flycheck())
|
||||||
Some(config) => format!("{}", config),
|
|
||||||
None => "cargo check".to_string(),
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
format!("cargo check (#{})", id + 1)
|
format!("cargo check (#{})", id + 1)
|
||||||
};
|
};
|
||||||
|
@ -593,7 +590,7 @@ impl GlobalState {
|
||||||
state,
|
state,
|
||||||
message,
|
message,
|
||||||
None,
|
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| {
|
.on::<lsp_types::notification::WorkDoneProgressCancel>(|this, params| {
|
||||||
if let lsp_types::NumberOrString::String(s) = ¶ms.token {
|
if let lsp_types::NumberOrString::String(s) = ¶ms.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 Ok(id) = u32::from_str_radix(id, 10) {
|
||||||
if let Some(flycheck) = this.flycheck.get(id as usize) {
|
if let Some(flycheck) = this.flycheck.get(id as usize) {
|
||||||
flycheck.cancel();
|
flycheck.cancel();
|
||||||
|
@ -888,15 +885,15 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if run_flycheck(this, vfs_path) {
|
if !this.config.check_on_save() || run_flycheck(this, vfs_path) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
} else if this.config.check_on_save() {
|
||||||
|
|
||||||
// No specific flycheck was triggered, so let's trigger all of them.
|
// No specific flycheck was triggered, so let's trigger all of them.
|
||||||
for flycheck in this.flycheck.iter() {
|
for flycheck in this.flycheck.iter() {
|
||||||
flycheck.restart();
|
flycheck.restart();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
.on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
|
.on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
|
||||||
|
|
|
@ -449,15 +449,7 @@ impl GlobalState {
|
||||||
|
|
||||||
fn reload_flycheck(&mut self) {
|
fn reload_flycheck(&mut self) {
|
||||||
let _p = profile::span("GlobalState::reload_flycheck");
|
let _p = profile::span("GlobalState::reload_flycheck");
|
||||||
let config = match self.config.flycheck() {
|
let config = self.config.flycheck();
|
||||||
Some(it) => it,
|
|
||||||
None => {
|
|
||||||
self.flycheck = Arc::new([]);
|
|
||||||
self.diagnostics.clear_check_all();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let sender = self.flycheck_sender.clone();
|
let sender = self.flycheck_sender.clone();
|
||||||
let invocation_strategy = match config {
|
let invocation_strategy = match config {
|
||||||
FlycheckConfig::CargoCommand { .. } => flycheck::InvocationStrategy::PerWorkspace,
|
FlycheckConfig::CargoCommand { .. } => flycheck::InvocationStrategy::PerWorkspace,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue