aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-29 14:05:14 +0100
committerAleksey Kladov <[email protected]>2019-05-29 14:05:14 +0100
commit5c410385fc2780238864e3e090fc4cff37b5c3fb (patch)
tree1fd5fccfa797b2f185d0f1c8b061c4e5fba26020 /crates
parent2c9a1cb3dd941b3f2f608a0633f620478bce0c68 (diff)
optimization: cancel backlog in onEnter
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs15
-rw-r--r--crates/ra_lsp_server/src/server_world.rs4
2 files changed, 16 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 @@
1mod handlers; 1mod handlers;
2mod subscriptions; 2mod subscriptions;
3 3
4use std::{fmt, path::PathBuf, sync::Arc, time::Instant}; 4use std::{fmt, path::PathBuf, sync::Arc, time::Instant, any::TypeId};
5 5
6use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; 6use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender};
7use failure::{bail, format_err}; 7use 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
454impl<'a> PoolDispatcher<'a> { 454impl<'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 || {
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index b63927a4f..7eb4d3e56 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/server_world.rs
@@ -149,6 +149,10 @@ impl ServerWorldState {
149 self.analysis_host.apply_change(change); 149 self.analysis_host.apply_change(change);
150 } 150 }
151 151
152 pub fn cancel_requests(&mut self) {
153 self.analysis_host.apply_change(AnalysisChange::new());
154 }
155
152 pub fn snapshot(&self) -> ServerWorld { 156 pub fn snapshot(&self) -> ServerWorld {
153 ServerWorld { 157 ServerWorld {
154 workspaces: Arc::clone(&self.workspaces), 158 workspaces: Arc::clone(&self.workspaces),