5390: Don't drop flycheck messages during restart r=matklad a=matklad

closes #5386



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-15 12:38:24 +00:00 committed by GitHub
commit fbdc3c7849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 22 deletions

View file

@ -63,7 +63,9 @@ 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<Handle<FlycheckHandle, Receiver<flycheck::Message>>>,
pub(crate) flycheck: Option<FlycheckHandle>,
pub(crate) flycheck_sender: Sender<flycheck::Message>,
pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
pub(crate) config: Config,
pub(crate) analysis_host: AnalysisHost,
pub(crate) diagnostics: DiagnosticCollection,
@ -103,12 +105,15 @@ impl GlobalState {
};
let analysis_host = AnalysisHost::new(config.lru_capacity);
let (flycheck_sender, flycheck_receiver) = unbounded();
GlobalState {
sender,
req_queue: ReqQueue::default(),
task_pool,
loader,
flycheck: None,
flycheck_sender,
flycheck_receiver,
config,
analysis_host,
diagnostics: Default::default(),

View file

@ -5,7 +5,7 @@ use std::{
time::{Duration, Instant},
};
use crossbeam_channel::{never, select, Receiver};
use crossbeam_channel::{select, Receiver};
use lsp_server::{Connection, Notification, Request, Response};
use lsp_types::notification::Notification as _;
use ra_db::VfsPath;
@ -108,7 +108,7 @@ impl GlobalState {
recv(self.loader.receiver) -> task =>
Some(Event::Vfs(task.unwrap())),
recv(self.flycheck.as_ref().map_or(&never(), |it| &it.receiver)) -> task =>
recv(self.flycheck_receiver) -> task =>
Some(Event::Flycheck(task.unwrap())),
}
}
@ -292,7 +292,7 @@ impl GlobalState {
let state_changed = self.process_changes();
if prev_status == Status::Loading && self.status == Status::Ready {
if let Some(flycheck) = &self.flycheck {
flycheck.handle.update();
flycheck.update();
}
}
@ -441,7 +441,7 @@ impl GlobalState {
})?
.on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
if let Some(flycheck) = &this.flycheck {
flycheck.handle.update();
flycheck.update();
}
if let Ok(abs_path) = from_proto::abs_path(&params.text_document.uri) {
this.maybe_refresh(&[(abs_path, ChangeKind::Modify)]);

View file

@ -1,20 +1,19 @@
//! Project loading & configuration updates
use std::{mem, sync::Arc};
use crossbeam_channel::unbounded;
use flycheck::FlycheckHandle;
use ra_db::{CrateGraph, SourceRoot, VfsPath};
use ra_ide::AnalysisChange;
use ra_prof::profile;
use ra_project_model::{PackageRoot, ProcMacroClient, ProjectWorkspace};
use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind};
use crate::{
config::{Config, FilesWatcher, LinkedProject},
global_state::{GlobalState, Handle, Status},
global_state::{GlobalState, Status},
lsp_ext,
main_loop::Task,
};
use ra_prof::profile;
impl GlobalState {
pub(crate) fn update_configuration(&mut self, config: Config) {
@ -231,21 +230,20 @@ impl GlobalState {
}
};
// FIXME: Figure out the multi-workspace situation
self.flycheck = self.workspaces.iter().find_map(move |w| match w {
ProjectWorkspace::Cargo { cargo, .. } => {
let (sender, receiver) = unbounded();
let sender = Box::new(move |msg| sender.send(msg).unwrap());
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),
ProjectWorkspace::Json { .. } => None,
})
.map(move |cargo| {
let cargo_project_root = cargo.workspace_root().to_path_buf();
let handle =
FlycheckHandle::spawn(sender, config.clone(), cargo_project_root.into());
Some(Handle { handle, receiver })
}
ProjectWorkspace::Json { .. } => {
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
None
}
})
FlycheckHandle::spawn(sender, config.clone(), cargo_project_root.into())
})
}
}