diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-29 14:05:58 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-29 14:05:58 +0100 |
commit | cb21a219987eac0f8dc08f0c858e8a7154fccd04 (patch) | |
tree | 1fd5fccfa797b2f185d0f1c8b061c4e5fba26020 /crates/ra_lsp_server/src/main_loop.rs | |
parent | 557a4b8301d33e545fb5bb2b86cc811ecd9de7eb (diff) | |
parent | 5c410385fc2780238864e3e090fc4cff37b5c3fb (diff) |
Merge #1343
1343: optimization: cancel backlog in onEnter r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop.rs')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index e65bb0972..d29ba94e7 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | mod handlers; | 1 | mod handlers; |
2 | mod subscriptions; | 2 | mod subscriptions; |
3 | 3 | ||
4 | use std::{fmt, path::PathBuf, sync::Arc, time::Instant}; | 4 | use std::{fmt, path::PathBuf, sync::Arc, time::Instant, any::TypeId}; |
5 | 5 | ||
6 | use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; | 6 | use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; |
7 | use failure::{bail, format_err}; | 7 | use failure::{bail, format_err}; |
@@ -447,14 +447,14 @@ struct PoolDispatcher<'a> { | |||
447 | req: Option<RawRequest>, | 447 | req: Option<RawRequest>, |
448 | res: Option<u64>, | 448 | res: Option<u64>, |
449 | pool: &'a ThreadPool, | 449 | pool: &'a ThreadPool, |
450 | world: &'a ServerWorldState, | 450 | world: &'a mut ServerWorldState, |
451 | sender: &'a Sender<Task>, | 451 | sender: &'a Sender<Task>, |
452 | } | 452 | } |
453 | 453 | ||
454 | impl<'a> PoolDispatcher<'a> { | 454 | impl<'a> PoolDispatcher<'a> { |
455 | fn on<R>(&mut self, f: fn(ServerWorld, R::Params) -> Result<R::Result>) -> Result<&mut Self> | 455 | fn on<R>(&mut self, f: fn(ServerWorld, R::Params) -> Result<R::Result>) -> Result<&mut Self> |
456 | where | 456 | where |
457 | R: req::Request, | 457 | R: req::Request + 'static, |
458 | R::Params: DeserializeOwned + Send + 'static, | 458 | R::Params: DeserializeOwned + Send + 'static, |
459 | R::Result: Serialize + 'static, | 459 | R::Result: Serialize + 'static, |
460 | { | 460 | { |
@@ -464,6 +464,15 @@ impl<'a> PoolDispatcher<'a> { | |||
464 | }; | 464 | }; |
465 | match req.cast::<R>() { | 465 | match req.cast::<R>() { |
466 | Ok((id, params)) => { | 466 | Ok((id, params)) => { |
467 | // Real time requests block user typing, so we should react quickly to them. | ||
468 | // Currently this means that we try to cancel background jobs if we don't have | ||
469 | // a spare thread. | ||
470 | let is_real_time = TypeId::of::<R>() == TypeId::of::<req::JoinLines>() | ||
471 | || TypeId::of::<R>() == TypeId::of::<req::OnEnter>(); | ||
472 | if self.pool.queued_count() > 0 && is_real_time { | ||
473 | self.world.cancel_requests(); | ||
474 | } | ||
475 | |||
467 | let world = self.world.snapshot(); | 476 | let world = self.world.snapshot(); |
468 | let sender = self.sender.clone(); | 477 | let sender = self.sender.clone(); |
469 | self.pool.execute(move || { | 478 | self.pool.execute(move || { |