Spawn a flycheck instance per workspace
This commit is contained in:
committed by
Jonas Schievink
parent
662ed41ebc
commit
1a28f30ba4
@@ -63,7 +63,7 @@ pub(crate) struct GlobalState {
|
||||
req_queue: ReqQueue,
|
||||
pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>,
|
||||
pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>,
|
||||
pub(crate) flycheck: Option<FlycheckHandle>,
|
||||
pub(crate) flycheck: Vec<FlycheckHandle>,
|
||||
pub(crate) flycheck_sender: Sender<flycheck::Message>,
|
||||
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
|
||||
pub(crate) config: Config,
|
||||
@@ -115,7 +115,7 @@ impl GlobalState {
|
||||
req_queue: ReqQueue::default(),
|
||||
task_pool,
|
||||
loader,
|
||||
flycheck: None,
|
||||
flycheck: Vec::new(),
|
||||
flycheck_sender,
|
||||
flycheck_receiver,
|
||||
config,
|
||||
|
||||
@@ -266,8 +266,8 @@ impl GlobalState {
|
||||
}
|
||||
}
|
||||
|
||||
flycheck::Message::Progress(status) => {
|
||||
let (state, message) = match status {
|
||||
flycheck::Message::Progress { id, progress } => {
|
||||
let (state, message) = match progress {
|
||||
flycheck::Progress::DidStart => {
|
||||
self.diagnostics.clear_check();
|
||||
(Progress::Begin, None)
|
||||
@@ -284,14 +284,21 @@ impl GlobalState {
|
||||
}
|
||||
};
|
||||
|
||||
self.report_progress("cargo check", state, message, None);
|
||||
// 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 {
|
||||
"cargo check".to_string()
|
||||
} else {
|
||||
format!("cargo check (#{})", id + 1)
|
||||
};
|
||||
self.report_progress(&title, state, message, None);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
let state_changed = self.process_changes();
|
||||
if prev_status == Status::Loading && self.status == Status::Ready {
|
||||
if let Some(flycheck) = &self.flycheck {
|
||||
for flycheck in &self.flycheck {
|
||||
flycheck.update();
|
||||
}
|
||||
}
|
||||
@@ -490,7 +497,7 @@ impl GlobalState {
|
||||
Ok(())
|
||||
})?
|
||||
.on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
|
||||
if let Some(flycheck) = &this.flycheck {
|
||||
for flycheck in &this.flycheck {
|
||||
flycheck.update();
|
||||
}
|
||||
if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) {
|
||||
|
||||
@@ -235,29 +235,37 @@ impl GlobalState {
|
||||
let config = match self.config.flycheck.clone() {
|
||||
Some(it) => it,
|
||||
None => {
|
||||
self.flycheck = None;
|
||||
self.flycheck = Vec::new();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let sender = self.flycheck_sender.clone();
|
||||
let sender = Box::new(move |msg| sender.send(msg).unwrap());
|
||||
self.flycheck = self
|
||||
.workspaces
|
||||
.iter()
|
||||
// FIXME: Figure out the multi-workspace situation
|
||||
.find_map(|w| match w {
|
||||
ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo.workspace_root()),
|
||||
.enumerate()
|
||||
.filter_map(|(id, w)| match w {
|
||||
ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some((id, cargo.workspace_root())),
|
||||
ProjectWorkspace::Json { project, .. } => {
|
||||
// Enable flychecks for json projects if a custom flycheck command was supplied
|
||||
// in the workspace configuration.
|
||||
match config {
|
||||
FlycheckConfig::CustomCommand { .. } => Some(project.path()),
|
||||
FlycheckConfig::CustomCommand { .. } => Some((id, project.path())),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
})
|
||||
.map(move |root| FlycheckHandle::spawn(sender, config, root.to_path_buf().into()))
|
||||
.map(|(id, root)| {
|
||||
let sender = sender.clone();
|
||||
FlycheckHandle::spawn(
|
||||
id,
|
||||
Box::new(move |msg| sender.send(msg).unwrap()),
|
||||
config.clone(),
|
||||
root.to_path_buf().into(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user