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!( write!(
f, f,
"invalid config value{}:\n{}", "invalid config value{}:\n{}",
self.errors.len(),
if self.errors.len() == 1 { "" } else { "s" }, if self.errors.len() == 1 { "" } else { "s" },
errors errors
) )

View file

@ -75,6 +75,7 @@ pub(crate) struct GlobalState {
pub(crate) flycheck: Arc<[FlycheckHandle]>, pub(crate) flycheck: Arc<[FlycheckHandle]>,
pub(crate) flycheck_sender: Sender<flycheck::Message>, pub(crate) flycheck_sender: Sender<flycheck::Message>,
pub(crate) flycheck_receiver: Receiver<flycheck::Message>, pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
pub(crate) last_flycheck_error: Option<String>,
// VFS // VFS
pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>, 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: Arc::from(Vec::new()),
flycheck_sender, flycheck_sender,
flycheck_receiver, flycheck_receiver,
last_flycheck_error: None,
vfs: Arc::new(RwLock::new((vfs::Vfs::default(), IntMap::default()))), vfs: Arc::new(RwLock::new((vfs::Vfs::default(), IntMap::default()))),
vfs_config_version: 0, 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 // 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. // provide a configuration. This is handled in Config::update below.
let mut config = Config::clone(&*this.config); let mut config = Config::clone(&*this.config);
config.update(json.take()); this.config_errors = config.update(json.take()).err();
this.update_configuration(config); this.update_configuration(config);
} }
} }

View file

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

View file

@ -139,6 +139,11 @@ impl GlobalState {
status.health = lsp_ext::Health::Warning; status.health = lsp_ext::Health::Warning;
format_to!(message, "{err}\n"); 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() { for ws in self.workspaces.iter() {
let (ProjectWorkspace::Cargo { sysroot, .. } let (ProjectWorkspace::Cargo { sysroot, .. }