Report flycheck errors via status

This commit is contained in:
Lukas Wirth 2023-05-26 15:37:41 +02:00
parent a2b59b110f
commit f876adf617
5 changed files with 16 additions and 13 deletions

View File

@ -734,7 +734,6 @@ impl fmt::Display for ConfigError {
write!(
f,
"invalid config value{}:\n{}",
self.errors.len(),
if self.errors.len() == 1 { "" } else { "s" },
errors
)

View File

@ -75,6 +75,7 @@ pub(crate) struct GlobalState {
pub(crate) flycheck: Arc<[FlycheckHandle]>,
pub(crate) flycheck_sender: Sender<flycheck::Message>,
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
pub(crate) last_flycheck_error: Option<String>,
// VFS
pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>,
@ -179,6 +180,7 @@ impl GlobalState {
flycheck: Arc::from(Vec::new()),
flycheck_sender,
flycheck_receiver,
last_flycheck_error: None,
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), IntMap::default()))),
vfs_config_version: 0,

View File

@ -169,7 +169,7 @@ pub(crate) fn handle_did_change_configuration(
// Note that json can be null according to the spec if the client can't
// provide a configuration. This is handled in Config::update below.
let mut config = Config::clone(&*this.config);
config.update(json.take());
this.config_errors = config.update(json.take()).err();
this.update_configuration(config);
}
}

View File

@ -602,21 +602,18 @@ impl GlobalState {
(Progress::Begin, None)
}
flycheck::Progress::DidCheckCrate(target) => (Progress::Report, Some(target)),
flycheck::Progress::DidCancel => (Progress::End, None),
flycheck::Progress::DidCancel => {
self.last_flycheck_error = None;
(Progress::End, None)
}
flycheck::Progress::DidFailToRestart(err) => {
self.show_and_log_error(
"cargo check failed to start".to_string(),
Some(err),
);
self.last_flycheck_error =
Some(format!("cargo check failed to start: {err}"));
return;
}
flycheck::Progress::DidFinish(result) => {
if let Err(err) = result {
self.show_and_log_error(
"cargo check failed".to_string(),
Some(err.to_string()),
);
}
self.last_flycheck_error =
result.err().map(|err| format!("cargo check failed to start: {err}"));
(Progress::End, None)
}
};

View File

@ -139,6 +139,11 @@ impl GlobalState {
status.health = lsp_ext::Health::Warning;
format_to!(message, "{err}\n");
}
if let Some(err) = &self.last_flycheck_error {
status.health = lsp_ext::Health::Warning;
message.push_str(err);
message.push('\n');
}
for ws in self.workspaces.iter() {
let (ProjectWorkspace::Cargo { sysroot, .. }