diff options
Diffstat (limited to 'crates/rust-analyzer/src/main_loop.rs')
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index eb9e7f913..7ccdbd29c 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -28,6 +28,14 @@ use crate::{ | |||
28 | request_metrics::RequestMetrics, | 28 | request_metrics::RequestMetrics, |
29 | LspError, Result, | 29 | LspError, Result, |
30 | }; | 30 | }; |
31 | pub use lsp_utils::show_message; | ||
32 | use lsp_utils::{is_canceled, notification_cast, notification_is, notification_new, request_new}; | ||
33 | use ra_progress::{ | ||
34 | IsDone, ProgressStatus, U32Progress, U32ProgressReport, U32ProgressSource, U32ProgressStatus, | ||
35 | }; | ||
36 | |||
37 | const FLYCHECK_PROGRESS_TOKEN: &str = "rustAnalyzer/flycheck"; | ||
38 | const ROOTS_SCANNED_PROGRESS_TOKEN: &str = "rustAnalyzer/rootsScanned"; | ||
31 | 39 | ||
32 | pub fn main_loop(config: Config, connection: Connection) -> Result<()> { | 40 | pub fn main_loop(config: Config, connection: Connection) -> Result<()> { |
33 | log::info!("initial config: {:#?}", config); | 41 | log::info!("initial config: {:#?}", config); |
@@ -138,6 +146,18 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> { | |||
138 | recv(global_state.flycheck.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task { | 146 | recv(global_state.flycheck.as_ref().map_or(&never(), |it| &it.task_recv)) -> task => match task { |
139 | Ok(task) => Event::CheckWatcher(task), | 147 | Ok(task) => Event::CheckWatcher(task), |
140 | Err(RecvError) => return Err("check watcher died".into()), | 148 | Err(RecvError) => return Err("check watcher died".into()), |
149 | }, | ||
150 | recv(global_state.flycheck_progress_receiver) -> status => match status { | ||
151 | Ok(status) => Event::ProgressReport(ProgressReport::Flycheck(status)), | ||
152 | Err(RecvError) => return Err("check watcher died".into()), | ||
153 | }, | ||
154 | recv(roots_scanned_progress_receiver) -> status => match status { | ||
155 | Ok(status) => Event::ProgressReport(ProgressReport::RootsScanned(status)), | ||
156 | Err(RecvError) => { | ||
157 | // Roots analysis has finished, we no longer need this receiver | ||
158 | roots_scanned_progress_receiver = never(); | ||
159 | continue; | ||
160 | } | ||
141 | } | 161 | } |
142 | }; | 162 | }; |
143 | if let Event::Msg(Message::Request(req)) = &event { | 163 | if let Event::Msg(Message::Request(req)) = &event { |
@@ -169,6 +189,7 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> { | |||
169 | enum Task { | 189 | enum Task { |
170 | Respond(Response), | 190 | Respond(Response), |
171 | Notify(Notification), | 191 | Notify(Notification), |
192 | SendRequest(Request), | ||
172 | Diagnostic(DiagnosticTask), | 193 | Diagnostic(DiagnosticTask), |
173 | } | 194 | } |
174 | 195 | ||
@@ -177,6 +198,13 @@ enum Event { | |||
177 | Task(Task), | 198 | Task(Task), |
178 | Vfs(vfs::loader::Message), | 199 | Vfs(vfs::loader::Message), |
179 | CheckWatcher(CheckTask), | 200 | CheckWatcher(CheckTask), |
201 | ProgressReport(ProgressReport), | ||
202 | } | ||
203 | |||
204 | #[derive(Debug)] | ||
205 | enum ProgressReport { | ||
206 | Flycheck(ProgressStatus<(), String>), | ||
207 | RootsScanned(U32ProgressStatus), | ||
180 | } | 208 | } |
181 | 209 | ||
182 | impl fmt::Debug for Event { | 210 | impl fmt::Debug for Event { |
@@ -212,6 +240,7 @@ impl fmt::Debug for Event { | |||
212 | Event::Task(it) => fmt::Debug::fmt(it, f), | 240 | Event::Task(it) => fmt::Debug::fmt(it, f), |
213 | Event::Vfs(it) => fmt::Debug::fmt(it, f), | 241 | Event::Vfs(it) => fmt::Debug::fmt(it, f), |
214 | Event::CheckWatcher(it) => fmt::Debug::fmt(it, f), | 242 | Event::CheckWatcher(it) => fmt::Debug::fmt(it, f), |
243 | Event::ProgressReport(it) => fmt::Debug::fmt(it, f), | ||
215 | } | 244 | } |
216 | } | 245 | } |
217 | } | 246 | } |
@@ -262,6 +291,9 @@ fn loop_turn( | |||
262 | } | 291 | } |
263 | }, | 292 | }, |
264 | Event::CheckWatcher(task) => on_check_task(task, global_state, task_sender)?, | 293 | Event::CheckWatcher(task) => on_check_task(task, global_state, task_sender)?, |
294 | Event::ProgressReport(report) => { | ||
295 | on_progress_report(report, task_sender, loop_state, global_state) | ||
296 | } | ||
265 | Event::Msg(msg) => match msg { | 297 | Event::Msg(msg) => match msg { |
266 | Message::Request(req) => { | 298 | Message::Request(req) => { |
267 | on_request(global_state, pool, task_sender, &connection.sender, loop_start, req)? | 299 | on_request(global_state, pool, task_sender, &connection.sender, loop_start, req)? |
@@ -826,7 +858,7 @@ where | |||
826 | Err(e) => match e.downcast::<LspError>() { | 858 | Err(e) => match e.downcast::<LspError>() { |
827 | Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message), | 859 | Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message), |
828 | Err(e) => { | 860 | Err(e) => { |
829 | if is_canceled(&e) { | 861 | if is_canceled(&*e) { |
830 | Response::new_err( | 862 | Response::new_err( |
831 | id, | 863 | id, |
832 | ErrorCode::ContentModified as i32, | 864 | ErrorCode::ContentModified as i32, |
@@ -853,7 +885,7 @@ fn update_file_notifications_on_threadpool( | |||
853 | for file_id in subscriptions { | 885 | for file_id in subscriptions { |
854 | match handlers::publish_diagnostics(&world, file_id) { | 886 | match handlers::publish_diagnostics(&world, file_id) { |
855 | Err(e) => { | 887 | Err(e) => { |
856 | if !is_canceled(&e) { | 888 | if !is_canceled(&*e) { |
857 | log::error!("failed to compute diagnostics: {:?}", e); | 889 | log::error!("failed to compute diagnostics: {:?}", e); |
858 | } | 890 | } |
859 | } | 891 | } |