diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-29 10:24:08 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-29 10:24:08 +0000 |
commit | 7a2b87db734162f02f554f7876f3ae0f21a36a60 (patch) | |
tree | 10f01bd26fba1fdc05424443141b87639030875a | |
parent | 3ea8940d94b4b8af7f7fcdf9b92faa025d9f99de (diff) | |
parent | 9753eb98ccbe4c5abefacde2fc60e919cf3c5645 (diff) |
Merge #2934
2934: Complain loudly if the main loop is blocked r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 52c7e2bdb..9901fe931 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -5,7 +5,14 @@ mod handlers; | |||
5 | mod subscriptions; | 5 | mod subscriptions; |
6 | pub(crate) mod pending_requests; | 6 | pub(crate) mod pending_requests; |
7 | 7 | ||
8 | use std::{error::Error, fmt, panic, path::PathBuf, sync::Arc, time::Instant}; | 8 | use std::{ |
9 | env, | ||
10 | error::Error, | ||
11 | fmt, panic, | ||
12 | path::PathBuf, | ||
13 | sync::Arc, | ||
14 | time::{Duration, Instant}, | ||
15 | }; | ||
9 | 16 | ||
10 | use crossbeam_channel::{select, unbounded, RecvError, Sender}; | 17 | use crossbeam_channel::{select, unbounded, RecvError, Sender}; |
11 | use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; | 18 | use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; |
@@ -425,6 +432,19 @@ fn loop_turn( | |||
425 | loop_state.subscriptions.subscriptions(), | 432 | loop_state.subscriptions.subscriptions(), |
426 | ) | 433 | ) |
427 | } | 434 | } |
435 | |||
436 | let loop_duration = loop_start.elapsed(); | ||
437 | if loop_duration > Duration::from_millis(10) { | ||
438 | log::error!("overly long loop turn: {:?}", loop_duration); | ||
439 | if env::var("RA_PROFILE").is_ok() { | ||
440 | show_message( | ||
441 | req::MessageType::Error, | ||
442 | format!("overly long loop turn: {:?}", loop_duration), | ||
443 | &connection.sender, | ||
444 | ); | ||
445 | } | ||
446 | } | ||
447 | |||
428 | Ok(()) | 448 | Ok(()) |
429 | } | 449 | } |
430 | 450 | ||
@@ -452,7 +472,7 @@ fn on_request( | |||
452 | world: &mut WorldState, | 472 | world: &mut WorldState, |
453 | pending_requests: &mut PendingRequests, | 473 | pending_requests: &mut PendingRequests, |
454 | pool: &ThreadPool, | 474 | pool: &ThreadPool, |
455 | sender: &Sender<Task>, | 475 | task_sender: &Sender<Task>, |
456 | msg_sender: &Sender<Message>, | 476 | msg_sender: &Sender<Message>, |
457 | request_received: Instant, | 477 | request_received: Instant, |
458 | req: Request, | 478 | req: Request, |
@@ -461,7 +481,7 @@ fn on_request( | |||
461 | req: Some(req), | 481 | req: Some(req), |
462 | pool, | 482 | pool, |
463 | world, | 483 | world, |
464 | sender, | 484 | task_sender, |
465 | msg_sender, | 485 | msg_sender, |
466 | pending_requests, | 486 | pending_requests, |
467 | request_received, | 487 | request_received, |
@@ -661,7 +681,7 @@ struct PoolDispatcher<'a> { | |||
661 | world: &'a mut WorldState, | 681 | world: &'a mut WorldState, |
662 | pending_requests: &'a mut PendingRequests, | 682 | pending_requests: &'a mut PendingRequests, |
663 | msg_sender: &'a Sender<Message>, | 683 | msg_sender: &'a Sender<Message>, |
664 | sender: &'a Sender<Task>, | 684 | task_sender: &'a Sender<Task>, |
665 | request_received: Instant, | 685 | request_received: Instant, |
666 | } | 686 | } |
667 | 687 | ||
@@ -708,7 +728,7 @@ impl<'a> PoolDispatcher<'a> { | |||
708 | 728 | ||
709 | self.pool.execute({ | 729 | self.pool.execute({ |
710 | let world = self.world.snapshot(); | 730 | let world = self.world.snapshot(); |
711 | let sender = self.sender.clone(); | 731 | let sender = self.task_sender.clone(); |
712 | move || { | 732 | move || { |
713 | let result = f(world, params); | 733 | let result = f(world, params); |
714 | let task = result_to_task::<R>(id, result); | 734 | let task = result_to_task::<R>(id, result); |
@@ -786,7 +806,7 @@ fn update_file_notifications_on_threadpool( | |||
786 | pool: &ThreadPool, | 806 | pool: &ThreadPool, |
787 | world: WorldSnapshot, | 807 | world: WorldSnapshot, |
788 | publish_decorations: bool, | 808 | publish_decorations: bool, |
789 | sender: Sender<Task>, | 809 | task_sender: Sender<Task>, |
790 | subscriptions: Vec<FileId>, | 810 | subscriptions: Vec<FileId>, |
791 | ) { | 811 | ) { |
792 | log::trace!("updating notifications for {:?}", subscriptions); | 812 | log::trace!("updating notifications for {:?}", subscriptions); |
@@ -802,7 +822,7 @@ fn update_file_notifications_on_threadpool( | |||
802 | } | 822 | } |
803 | Ok(params) => { | 823 | Ok(params) => { |
804 | let not = notification_new::<req::PublishDiagnostics>(params); | 824 | let not = notification_new::<req::PublishDiagnostics>(params); |
805 | sender.send(Task::Notify(not)).unwrap(); | 825 | task_sender.send(Task::Notify(not)).unwrap(); |
806 | } | 826 | } |
807 | } | 827 | } |
808 | } | 828 | } |
@@ -815,7 +835,7 @@ fn update_file_notifications_on_threadpool( | |||
815 | } | 835 | } |
816 | Ok(params) => { | 836 | Ok(params) => { |
817 | let not = notification_new::<req::PublishDecorations>(params); | 837 | let not = notification_new::<req::PublishDecorations>(params); |
818 | sender.send(Task::Notify(not)).unwrap(); | 838 | task_sender.send(Task::Notify(not)).unwrap(); |
819 | } | 839 | } |
820 | } | 840 | } |
821 | } | 841 | } |