aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-15 13:37:44 +0100
committerAleksey Kladov <[email protected]>2020-07-15 13:37:44 +0100
commita40e05dd5d8b2c5f74c61cd08efed9dc83124657 (patch)
tree0cd983f87b9328f683cf70b6207972241b2368cd /crates
parent6f3c8dc11d477a6d680ce018e93f007c31499bd5 (diff)
Don't drop flycheck messages during restart
closes #5386
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/global_state.rs7
-rw-r--r--crates/rust-analyzer/src/main_loop.rs8
-rw-r--r--crates/rust-analyzer/src/reload.rs32
3 files changed, 25 insertions, 22 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 9a9a6547a..94973b90a 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -63,7 +63,9 @@ pub(crate) struct GlobalState {
63 req_queue: ReqQueue, 63 req_queue: ReqQueue,
64 pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>, 64 pub(crate) task_pool: Handle<TaskPool<Task>, Receiver<Task>>,
65 pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>, 65 pub(crate) loader: Handle<Box<dyn vfs::loader::Handle>, Receiver<vfs::loader::Message>>,
66 pub(crate) flycheck: Option<Handle<FlycheckHandle, Receiver<flycheck::Message>>>, 66 pub(crate) flycheck: Option<FlycheckHandle>,
67 pub(crate) flycheck_sender: Sender<flycheck::Message>,
68 pub(crate) flycheck_receiver: Receiver<flycheck::Message>,
67 pub(crate) config: Config, 69 pub(crate) config: Config,
68 pub(crate) analysis_host: AnalysisHost, 70 pub(crate) analysis_host: AnalysisHost,
69 pub(crate) diagnostics: DiagnosticCollection, 71 pub(crate) diagnostics: DiagnosticCollection,
@@ -103,12 +105,15 @@ impl GlobalState {
103 }; 105 };
104 106
105 let analysis_host = AnalysisHost::new(config.lru_capacity); 107 let analysis_host = AnalysisHost::new(config.lru_capacity);
108 let (flycheck_sender, flycheck_receiver) = unbounded();
106 GlobalState { 109 GlobalState {
107 sender, 110 sender,
108 req_queue: ReqQueue::default(), 111 req_queue: ReqQueue::default(),
109 task_pool, 112 task_pool,
110 loader, 113 loader,
111 flycheck: None, 114 flycheck: None,
115 flycheck_sender,
116 flycheck_receiver,
112 config, 117 config,
113 analysis_host, 118 analysis_host,
114 diagnostics: Default::default(), 119 diagnostics: Default::default(),
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 5afcc2d87..a41f7f564 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -5,7 +5,7 @@ use std::{
5 time::{Duration, Instant}, 5 time::{Duration, Instant},
6}; 6};
7 7
8use crossbeam_channel::{never, select, Receiver}; 8use crossbeam_channel::{select, Receiver};
9use lsp_server::{Connection, Notification, Request, Response}; 9use lsp_server::{Connection, Notification, Request, Response};
10use lsp_types::notification::Notification as _; 10use lsp_types::notification::Notification as _;
11use ra_db::VfsPath; 11use ra_db::VfsPath;
@@ -108,7 +108,7 @@ impl GlobalState {
108 recv(self.loader.receiver) -> task => 108 recv(self.loader.receiver) -> task =>
109 Some(Event::Vfs(task.unwrap())), 109 Some(Event::Vfs(task.unwrap())),
110 110
111 recv(self.flycheck.as_ref().map_or(&never(), |it| &it.receiver)) -> task => 111 recv(self.flycheck_receiver) -> task =>
112 Some(Event::Flycheck(task.unwrap())), 112 Some(Event::Flycheck(task.unwrap())),
113 } 113 }
114 } 114 }
@@ -292,7 +292,7 @@ impl GlobalState {
292 let state_changed = self.process_changes(); 292 let state_changed = self.process_changes();
293 if prev_status == Status::Loading && self.status == Status::Ready { 293 if prev_status == Status::Loading && self.status == Status::Ready {
294 if let Some(flycheck) = &self.flycheck { 294 if let Some(flycheck) = &self.flycheck {
295 flycheck.handle.update(); 295 flycheck.update();
296 } 296 }
297 } 297 }
298 298
@@ -441,7 +441,7 @@ impl GlobalState {
441 })? 441 })?
442 .on::<lsp_types::notification::DidSaveTextDocument>(|this, params| { 442 .on::<lsp_types::notification::DidSaveTextDocument>(|this, params| {
443 if let Some(flycheck) = &this.flycheck { 443 if let Some(flycheck) = &this.flycheck {
444 flycheck.handle.update(); 444 flycheck.update();
445 } 445 }
446 if let Ok(abs_path) = from_proto::abs_path(&params.text_document.uri) { 446 if let Ok(abs_path) = from_proto::abs_path(&params.text_document.uri) {
447 this.maybe_refresh(&[(abs_path, ChangeKind::Modify)]); 447 this.maybe_refresh(&[(abs_path, ChangeKind::Modify)]);
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index ab1b18ea9..3f4dbdd8c 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -1,20 +1,19 @@
1//! Project loading & configuration updates 1//! Project loading & configuration updates
2use std::{mem, sync::Arc}; 2use std::{mem, sync::Arc};
3 3
4use crossbeam_channel::unbounded;
5use flycheck::FlycheckHandle; 4use flycheck::FlycheckHandle;
6use ra_db::{CrateGraph, SourceRoot, VfsPath}; 5use ra_db::{CrateGraph, SourceRoot, VfsPath};
7use ra_ide::AnalysisChange; 6use ra_ide::AnalysisChange;
7use ra_prof::profile;
8use ra_project_model::{PackageRoot, ProcMacroClient, ProjectWorkspace}; 8use ra_project_model::{PackageRoot, ProcMacroClient, ProjectWorkspace};
9use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind}; 9use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind};
10 10
11use crate::{ 11use crate::{
12 config::{Config, FilesWatcher, LinkedProject}, 12 config::{Config, FilesWatcher, LinkedProject},
13 global_state::{GlobalState, Handle, Status}, 13 global_state::{GlobalState, Status},
14 lsp_ext, 14 lsp_ext,
15 main_loop::Task, 15 main_loop::Task,
16}; 16};
17use ra_prof::profile;
18 17
19impl GlobalState { 18impl GlobalState {
20 pub(crate) fn update_configuration(&mut self, config: Config) { 19 pub(crate) fn update_configuration(&mut self, config: Config) {
@@ -231,21 +230,20 @@ impl GlobalState {
231 } 230 }
232 }; 231 };
233 232
234 // FIXME: Figure out the multi-workspace situation 233 let sender = self.flycheck_sender.clone();
235 self.flycheck = self.workspaces.iter().find_map(move |w| match w { 234 let sender = Box::new(move |msg| sender.send(msg).unwrap());
236 ProjectWorkspace::Cargo { cargo, .. } => { 235 self.flycheck = self
237 let (sender, receiver) = unbounded(); 236 .workspaces
238 let sender = Box::new(move |msg| sender.send(msg).unwrap()); 237 .iter()
238 // FIXME: Figure out the multi-workspace situation
239 .find_map(|w| match w {
240 ProjectWorkspace::Cargo { cargo, sysroot: _ } => Some(cargo),
241 ProjectWorkspace::Json { .. } => None,
242 })
243 .map(move |cargo| {
239 let cargo_project_root = cargo.workspace_root().to_path_buf(); 244 let cargo_project_root = cargo.workspace_root().to_path_buf();
240 let handle = 245 FlycheckHandle::spawn(sender, config.clone(), cargo_project_root.into())
241 FlycheckHandle::spawn(sender, config.clone(), cargo_project_root.into()); 246 })
242 Some(Handle { handle, receiver })
243 }
244 ProjectWorkspace::Json { .. } => {
245 log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
246 None
247 }
248 })
249 } 247 }
250} 248}
251 249