From 8bb02859e8656b57b90a95076f559003b015f39b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 May 2019 19:20:22 +0300 Subject: introduce constant --- crates/ra_lsp_server/src/main_loop.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 00cea10df..95b69cd6e 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -26,6 +26,9 @@ use crate::{ InitializationOptions, }; +const THREADPOOL_SIZE: usize = 8; +const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3; + #[derive(Debug, Fail)] #[fail(display = "Language Server request failed with {}. ({})", code, message)] pub struct LspError { @@ -46,18 +49,21 @@ enum Task { } struct PendingRequest { + id: u64, received: Instant, method: String, } -impl From<(u64, PendingRequest)> for CompletedRequest { - fn from((id, pending): (u64, PendingRequest)) -> CompletedRequest { - CompletedRequest { id, method: pending.method, duration: pending.received.elapsed() } +impl From for CompletedRequest { + fn from(pending: PendingRequest) -> CompletedRequest { + CompletedRequest { + id: pending.id, + method: pending.method, + duration: pending.received.elapsed(), + } } } -const THREADPOOL_SIZE: usize = 8; - pub fn main_loop( ws_roots: Vec, options: InitializationOptions, @@ -175,7 +181,7 @@ fn main_loop_inner( pending_requests: &mut FxHashMap, subs: &mut Subscriptions, ) -> Result<()> { - // We try not to index more than THREADPOOL_SIZE - 3 libraries at the same + // We try not to index more than MAX_IN_FLIGHT_LIBS libraries at the same // time to always have a thread ready to react to input. let mut in_flight_libraries = 0; let mut pending_libraries = Vec::new(); @@ -264,7 +270,7 @@ fn main_loop_inner( }; pending_libraries.extend(state.process_changes()); - while in_flight_libraries < THREADPOOL_SIZE - 3 && !pending_libraries.is_empty() { + while in_flight_libraries < MAX_IN_FLIGHT_LIBS && !pending_libraries.is_empty() { let (root, files) = pending_libraries.pop().unwrap(); in_flight_libraries += 1; let sender = libdata_sender.clone(); -- cgit v1.2.3