diff options
author | Aleksey Kladov <[email protected]> | 2019-05-31 17:20:22 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-05-31 17:20:22 +0100 |
commit | 8bb02859e8656b57b90a95076f559003b015f39b (patch) | |
tree | 124a2af25434378ae8482a379096fea5f2a0f3e4 /crates | |
parent | 0e542936beda5a5e3125ae400fc2630768945ba6 (diff) |
introduce constant
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 20 |
1 files 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::{ | |||
26 | InitializationOptions, | 26 | InitializationOptions, |
27 | }; | 27 | }; |
28 | 28 | ||
29 | const THREADPOOL_SIZE: usize = 8; | ||
30 | const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3; | ||
31 | |||
29 | #[derive(Debug, Fail)] | 32 | #[derive(Debug, Fail)] |
30 | #[fail(display = "Language Server request failed with {}. ({})", code, message)] | 33 | #[fail(display = "Language Server request failed with {}. ({})", code, message)] |
31 | pub struct LspError { | 34 | pub struct LspError { |
@@ -46,18 +49,21 @@ enum Task { | |||
46 | } | 49 | } |
47 | 50 | ||
48 | struct PendingRequest { | 51 | struct PendingRequest { |
52 | id: u64, | ||
49 | received: Instant, | 53 | received: Instant, |
50 | method: String, | 54 | method: String, |
51 | } | 55 | } |
52 | 56 | ||
53 | impl From<(u64, PendingRequest)> for CompletedRequest { | 57 | impl From<PendingRequest> for CompletedRequest { |
54 | fn from((id, pending): (u64, PendingRequest)) -> CompletedRequest { | 58 | fn from(pending: PendingRequest) -> CompletedRequest { |
55 | CompletedRequest { id, method: pending.method, duration: pending.received.elapsed() } | 59 | CompletedRequest { |
60 | id: pending.id, | ||
61 | method: pending.method, | ||
62 | duration: pending.received.elapsed(), | ||
63 | } | ||
56 | } | 64 | } |
57 | } | 65 | } |
58 | 66 | ||
59 | const THREADPOOL_SIZE: usize = 8; | ||
60 | |||
61 | pub fn main_loop( | 67 | pub fn main_loop( |
62 | ws_roots: Vec<PathBuf>, | 68 | ws_roots: Vec<PathBuf>, |
63 | options: InitializationOptions, | 69 | options: InitializationOptions, |
@@ -175,7 +181,7 @@ fn main_loop_inner( | |||
175 | pending_requests: &mut FxHashMap<u64, PendingRequest>, | 181 | pending_requests: &mut FxHashMap<u64, PendingRequest>, |
176 | subs: &mut Subscriptions, | 182 | subs: &mut Subscriptions, |
177 | ) -> Result<()> { | 183 | ) -> Result<()> { |
178 | // We try not to index more than THREADPOOL_SIZE - 3 libraries at the same | 184 | // We try not to index more than MAX_IN_FLIGHT_LIBS libraries at the same |
179 | // time to always have a thread ready to react to input. | 185 | // time to always have a thread ready to react to input. |
180 | let mut in_flight_libraries = 0; | 186 | let mut in_flight_libraries = 0; |
181 | let mut pending_libraries = Vec::new(); | 187 | let mut pending_libraries = Vec::new(); |
@@ -264,7 +270,7 @@ fn main_loop_inner( | |||
264 | }; | 270 | }; |
265 | 271 | ||
266 | pending_libraries.extend(state.process_changes()); | 272 | pending_libraries.extend(state.process_changes()); |
267 | while in_flight_libraries < THREADPOOL_SIZE - 3 && !pending_libraries.is_empty() { | 273 | while in_flight_libraries < MAX_IN_FLIGHT_LIBS && !pending_libraries.is_empty() { |
268 | let (root, files) = pending_libraries.pop().unwrap(); | 274 | let (root, files) = pending_libraries.pop().unwrap(); |
269 | in_flight_libraries += 1; | 275 | in_flight_libraries += 1; |
270 | let sender = libdata_sender.clone(); | 276 | let sender = libdata_sender.clone(); |