mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
introduce constant
This commit is contained in:
parent
0e542936be
commit
8bb02859e8
1 changed files with 13 additions and 7 deletions
|
@ -26,6 +26,9 @@ use crate::{
|
||||||
InitializationOptions,
|
InitializationOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const THREADPOOL_SIZE: usize = 8;
|
||||||
|
const MAX_IN_FLIGHT_LIBS: usize = THREADPOOL_SIZE - 3;
|
||||||
|
|
||||||
#[derive(Debug, Fail)]
|
#[derive(Debug, Fail)]
|
||||||
#[fail(display = "Language Server request failed with {}. ({})", code, message)]
|
#[fail(display = "Language Server request failed with {}. ({})", code, message)]
|
||||||
pub struct LspError {
|
pub struct LspError {
|
||||||
|
@ -46,18 +49,21 @@ enum Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PendingRequest {
|
struct PendingRequest {
|
||||||
|
id: u64,
|
||||||
received: Instant,
|
received: Instant,
|
||||||
method: String,
|
method: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(u64, PendingRequest)> for CompletedRequest {
|
impl From<PendingRequest> for CompletedRequest {
|
||||||
fn from((id, pending): (u64, PendingRequest)) -> CompletedRequest {
|
fn from(pending: PendingRequest) -> CompletedRequest {
|
||||||
CompletedRequest { id, method: pending.method, duration: pending.received.elapsed() }
|
CompletedRequest {
|
||||||
|
id: pending.id,
|
||||||
|
method: pending.method,
|
||||||
|
duration: pending.received.elapsed(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const THREADPOOL_SIZE: usize = 8;
|
|
||||||
|
|
||||||
pub fn main_loop(
|
pub fn main_loop(
|
||||||
ws_roots: Vec<PathBuf>,
|
ws_roots: Vec<PathBuf>,
|
||||||
options: InitializationOptions,
|
options: InitializationOptions,
|
||||||
|
@ -175,7 +181,7 @@ fn main_loop_inner(
|
||||||
pending_requests: &mut FxHashMap<u64, PendingRequest>,
|
pending_requests: &mut FxHashMap<u64, PendingRequest>,
|
||||||
subs: &mut Subscriptions,
|
subs: &mut Subscriptions,
|
||||||
) -> Result<()> {
|
) -> 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.
|
// time to always have a thread ready to react to input.
|
||||||
let mut in_flight_libraries = 0;
|
let mut in_flight_libraries = 0;
|
||||||
let mut pending_libraries = Vec::new();
|
let mut pending_libraries = Vec::new();
|
||||||
|
@ -264,7 +270,7 @@ fn main_loop_inner(
|
||||||
};
|
};
|
||||||
|
|
||||||
pending_libraries.extend(state.process_changes());
|
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();
|
let (root, files) = pending_libraries.pop().unwrap();
|
||||||
in_flight_libraries += 1;
|
in_flight_libraries += 1;
|
||||||
let sender = libdata_sender.clone();
|
let sender = libdata_sender.clone();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue