aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-25 13:13:52 +0100
committerGitHub <[email protected]>2020-06-25 13:13:52 +0100
commit9be0094b5cc24d82541d98a7bd00187c18388fd3 (patch)
tree5f23071a22d1a096d33c16641d4536ad8ebb1be8
parent4ec0a2c4541883a4f8837de0ecfb2e1fc700539a (diff)
parent9cdeb1291e84f922ecd3ce2218ed2c116ae13e17 (diff)
Merge #5058
5058: Better event naming r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/rust-analyzer/src/main_loop.rs46
1 files changed, 25 insertions, 21 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 3b3b83209..a7a7d2eb7 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -7,7 +7,7 @@ use std::{
7}; 7};
8 8
9use crossbeam_channel::{never, select, unbounded, RecvError, Sender}; 9use crossbeam_channel::{never, select, unbounded, RecvError, Sender};
10use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; 10use lsp_server::{Connection, ErrorCode, Notification, Request, RequestId, Response};
11use lsp_types::{request::Request as _, NumberOrString}; 11use lsp_types::{request::Request as _, NumberOrString};
12use ra_db::VfsPath; 12use ra_db::VfsPath;
13use ra_ide::{Canceled, FileId}; 13use ra_ide::{Canceled, FileId};
@@ -128,7 +128,7 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
128 log::trace!("selecting"); 128 log::trace!("selecting");
129 let event = select! { 129 let event = select! {
130 recv(&connection.receiver) -> msg => match msg { 130 recv(&connection.receiver) -> msg => match msg {
131 Ok(msg) => Event::Msg(msg), 131 Ok(msg) => Event::Lsp(msg),
132 Err(RecvError) => return Err("client exited without shutdown".into()), 132 Err(RecvError) => return Err("client exited without shutdown".into()),
133 }, 133 },
134 recv(task_receiver) -> task => Event::Task(task.unwrap()), 134 recv(task_receiver) -> task => Event::Task(task.unwrap()),
@@ -137,11 +137,11 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
137 Err(RecvError) => return Err("vfs died".into()), 137 Err(RecvError) => return Err("vfs died".into()),
138 }, 138 },
139 recv(global_state.flycheck.as_ref().map_or(&never(), |it| &it.1)) -> task => match task { 139 recv(global_state.flycheck.as_ref().map_or(&never(), |it| &it.1)) -> task => match task {
140 Ok(task) => Event::CheckWatcher(task), 140 Ok(task) => Event::Flycheck(task),
141 Err(RecvError) => return Err("check watcher died".into()), 141 Err(RecvError) => return Err("check watcher died".into()),
142 }, 142 },
143 }; 143 };
144 if let Event::Msg(Message::Request(req)) = &event { 144 if let Event::Lsp(lsp_server::Message::Request(req)) = &event {
145 if connection.handle_shutdown(&req)? { 145 if connection.handle_shutdown(&req)? {
146 break; 146 break;
147 }; 147 };
@@ -173,10 +173,10 @@ enum Task {
173} 173}
174 174
175enum Event { 175enum Event {
176 Msg(Message), 176 Lsp(lsp_server::Message),
177 Task(Task), 177 Task(Task),
178 Vfs(vfs::loader::Message), 178 Vfs(vfs::loader::Message),
179 CheckWatcher(flycheck::Message), 179 Flycheck(flycheck::Message),
180} 180}
181 181
182impl fmt::Debug for Event { 182impl fmt::Debug for Event {
@@ -186,7 +186,7 @@ impl fmt::Debug for Event {
186 }; 186 };
187 187
188 match self { 188 match self {
189 Event::Msg(Message::Notification(not)) => { 189 Event::Lsp(lsp_server::Message::Notification(not)) => {
190 if notification_is::<lsp_types::notification::DidOpenTextDocument>(not) 190 if notification_is::<lsp_types::notification::DidOpenTextDocument>(not)
191 || notification_is::<lsp_types::notification::DidChangeTextDocument>(not) 191 || notification_is::<lsp_types::notification::DidChangeTextDocument>(not)
192 { 192 {
@@ -203,10 +203,10 @@ impl fmt::Debug for Event {
203 _ => (), 203 _ => (),
204 } 204 }
205 match self { 205 match self {
206 Event::Msg(it) => fmt::Debug::fmt(it, f), 206 Event::Lsp(it) => fmt::Debug::fmt(it, f),
207 Event::Task(it) => fmt::Debug::fmt(it, f), 207 Event::Task(it) => fmt::Debug::fmt(it, f),
208 Event::Vfs(it) => fmt::Debug::fmt(it, f), 208 Event::Vfs(it) => fmt::Debug::fmt(it, f),
209 Event::CheckWatcher(it) => fmt::Debug::fmt(it, f), 209 Event::Flycheck(it) => fmt::Debug::fmt(it, f),
210 } 210 }
211 } 211 }
212} 212}
@@ -269,17 +269,17 @@ fn loop_turn(
269 ) 269 )
270 } 270 }
271 }, 271 },
272 Event::CheckWatcher(task) => { 272 Event::Flycheck(task) => {
273 on_check_task(task, global_state, task_sender, &connection.sender)? 273 on_check_task(task, global_state, task_sender, &connection.sender)?
274 } 274 }
275 Event::Msg(msg) => match msg { 275 Event::Lsp(msg) => match msg {
276 Message::Request(req) => { 276 lsp_server::Message::Request(req) => {
277 on_request(global_state, pool, task_sender, &connection.sender, loop_start, req)? 277 on_request(global_state, pool, task_sender, &connection.sender, loop_start, req)?
278 } 278 }
279 Message::Notification(not) => { 279 lsp_server::Message::Notification(not) => {
280 on_notification(&connection.sender, global_state, not)?; 280 on_notification(&connection.sender, global_state, not)?;
281 } 281 }
282 Message::Response(resp) => { 282 lsp_server::Message::Response(resp) => {
283 let handler = global_state.req_queue.outgoing.complete(resp.id.clone()); 283 let handler = global_state.req_queue.outgoing.complete(resp.id.clone());
284 handler(global_state, resp) 284 handler(global_state, resp)
285 } 285 }
@@ -329,7 +329,7 @@ fn loop_turn(
329 Ok(()) 329 Ok(())
330} 330}
331 331
332fn on_task(task: Task, msg_sender: &Sender<Message>, global_state: &mut GlobalState) { 332fn on_task(task: Task, msg_sender: &Sender<lsp_server::Message>, global_state: &mut GlobalState) {
333 match task { 333 match task {
334 Task::Respond(response) => { 334 Task::Respond(response) => {
335 if let Some((method, start)) = 335 if let Some((method, start)) =
@@ -353,7 +353,7 @@ fn on_request(
353 global_state: &mut GlobalState, 353 global_state: &mut GlobalState,
354 pool: &ThreadPool, 354 pool: &ThreadPool,
355 task_sender: &Sender<Task>, 355 task_sender: &Sender<Task>,
356 msg_sender: &Sender<Message>, 356 msg_sender: &Sender<lsp_server::Message>,
357 request_received: Instant, 357 request_received: Instant,
358 req: Request, 358 req: Request,
359) -> Result<()> { 359) -> Result<()> {
@@ -415,7 +415,7 @@ fn on_request(
415} 415}
416 416
417fn on_notification( 417fn on_notification(
418 msg_sender: &Sender<Message>, 418 msg_sender: &Sender<lsp_server::Message>,
419 global_state: &mut GlobalState, 419 global_state: &mut GlobalState,
420 not: Notification, 420 not: Notification,
421) -> Result<()> { 421) -> Result<()> {
@@ -553,7 +553,7 @@ fn on_check_task(
553 task: flycheck::Message, 553 task: flycheck::Message,
554 global_state: &mut GlobalState, 554 global_state: &mut GlobalState,
555 task_sender: &Sender<Task>, 555 task_sender: &Sender<Task>,
556 msg_sender: &Sender<Message>, 556 msg_sender: &Sender<lsp_server::Message>,
557) -> Result<()> { 557) -> Result<()> {
558 match task { 558 match task {
559 flycheck::Message::ClearDiagnostics => { 559 flycheck::Message::ClearDiagnostics => {
@@ -598,7 +598,11 @@ fn on_check_task(
598 Ok(()) 598 Ok(())
599} 599}
600 600
601fn on_diagnostic_task(task: DiagnosticTask, msg_sender: &Sender<Message>, state: &mut GlobalState) { 601fn on_diagnostic_task(
602 task: DiagnosticTask,
603 msg_sender: &Sender<lsp_server::Message>,
604 state: &mut GlobalState,
605) {
602 let subscriptions = state.diagnostics.handle_task(task); 606 let subscriptions = state.diagnostics.handle_task(task);
603 607
604 for file_id in subscriptions { 608 for file_id in subscriptions {
@@ -623,7 +627,7 @@ fn percentage(done: usize, total: usize) -> f64 {
623 627
624fn report_progress( 628fn report_progress(
625 global_state: &mut GlobalState, 629 global_state: &mut GlobalState,
626 sender: &Sender<Message>, 630 sender: &Sender<lsp_server::Message>,
627 title: &str, 631 title: &str,
628 state: Progress, 632 state: Progress,
629 message: Option<String>, 633 message: Option<String>,
@@ -672,7 +676,7 @@ struct PoolDispatcher<'a> {
672 req: Option<Request>, 676 req: Option<Request>,
673 pool: &'a ThreadPool, 677 pool: &'a ThreadPool,
674 global_state: &'a mut GlobalState, 678 global_state: &'a mut GlobalState,
675 msg_sender: &'a Sender<Message>, 679 msg_sender: &'a Sender<lsp_server::Message>,
676 task_sender: &'a Sender<Task>, 680 task_sender: &'a Sender<Task>,
677 request_received: Instant, 681 request_received: Instant,
678} 682}