Skip to content

Commit 7a2b87d

Browse files
bors[bot]matklad
andauthored
Merge #2934
2934: Complain loudly if the main loop is blocked r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 3ea8940 + 9753eb9 commit 7a2b87d

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

crates/ra_lsp_server/src/main_loop.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ mod handlers;
55
mod subscriptions;
66
pub(crate) mod pending_requests;
77

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+
};
916

1017
use crossbeam_channel::{select, unbounded, RecvError, Sender};
1118
use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
@@ -425,6 +432,19 @@ fn loop_turn(
425432
loop_state.subscriptions.subscriptions(),
426433
)
427434
}
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+
428448
Ok(())
429449
}
430450

@@ -452,7 +472,7 @@ fn on_request(
452472
world: &mut WorldState,
453473
pending_requests: &mut PendingRequests,
454474
pool: &ThreadPool,
455-
sender: &Sender<Task>,
475+
task_sender: &Sender<Task>,
456476
msg_sender: &Sender<Message>,
457477
request_received: Instant,
458478
req: Request,
@@ -461,7 +481,7 @@ fn on_request(
461481
req: Some(req),
462482
pool,
463483
world,
464-
sender,
484+
task_sender,
465485
msg_sender,
466486
pending_requests,
467487
request_received,
@@ -661,7 +681,7 @@ struct PoolDispatcher<'a> {
661681
world: &'a mut WorldState,
662682
pending_requests: &'a mut PendingRequests,
663683
msg_sender: &'a Sender<Message>,
664-
sender: &'a Sender<Task>,
684+
task_sender: &'a Sender<Task>,
665685
request_received: Instant,
666686
}
667687

@@ -708,7 +728,7 @@ impl<'a> PoolDispatcher<'a> {
708728

709729
self.pool.execute({
710730
let world = self.world.snapshot();
711-
let sender = self.sender.clone();
731+
let sender = self.task_sender.clone();
712732
move || {
713733
let result = f(world, params);
714734
let task = result_to_task::<R>(id, result);
@@ -786,7 +806,7 @@ fn update_file_notifications_on_threadpool(
786806
pool: &ThreadPool,
787807
world: WorldSnapshot,
788808
publish_decorations: bool,
789-
sender: Sender<Task>,
809+
task_sender: Sender<Task>,
790810
subscriptions: Vec<FileId>,
791811
) {
792812
log::trace!("updating notifications for {:?}", subscriptions);
@@ -802,7 +822,7 @@ fn update_file_notifications_on_threadpool(
802822
}
803823
Ok(params) => {
804824
let not = notification_new::<req::PublishDiagnostics>(params);
805-
sender.send(Task::Notify(not)).unwrap();
825+
task_sender.send(Task::Notify(not)).unwrap();
806826
}
807827
}
808828
}
@@ -815,7 +835,7 @@ fn update_file_notifications_on_threadpool(
815835
}
816836
Ok(params) => {
817837
let not = notification_new::<req::PublishDecorations>(params);
818-
sender.send(Task::Notify(not)).unwrap();
838+
task_sender.send(Task::Notify(not)).unwrap();
819839
}
820840
}
821841
}

0 commit comments

Comments
 (0)