aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs20
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
29const THREADPOOL_SIZE: usize = 8;
30const 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)]
31pub struct LspError { 34pub struct LspError {
@@ -46,18 +49,21 @@ enum Task {
46} 49}
47 50
48struct PendingRequest { 51struct PendingRequest {
52 id: u64,
49 received: Instant, 53 received: Instant,
50 method: String, 54 method: String,
51} 55}
52 56
53impl From<(u64, PendingRequest)> for CompletedRequest { 57impl 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
59const THREADPOOL_SIZE: usize = 8;
60
61pub fn main_loop( 67pub 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();