Skip to content

Commit c844b38

Browse files
committed
fix(lsp): allow cold managed runtimes to finish initialization
1 parent 0be1d34 commit c844b38

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎rust/contracts/rust-core-api.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2570,7 +2570,12 @@ its optional `hostOptions` (plugin-owned sessions only; `editor:{actionIcons,
25702570
actionSourceBytes, providerTypes}` declares the icons, collector source bound and
25712571
provider types the host implements, reported through `lithe/host/getCapabilities`
25722572
to sessions granted the matching editor methods), plus
2573-
initialize, request, and shutdown deadlines.
2573+
initialize, request, and shutdown deadlines. Omitted
2574+
`initializeTimeoutMilliseconds` allows 60000 milliseconds for one startup
2575+
handshake (previously 10000); cold runtime loading can exceed ten seconds.
2576+
An explicit deadline still takes precedence. Cancellation and timeout still
2577+
terminate and dispose of the owned process tree; this does not add retries or
2578+
change feature-request deadlines.
25742579
Rust owns the returned
25752580
session's child process, stdin/stdout/stderr, framing buffer, JSON-RPC request
25762581
IDs, document versions, pending deadlines, capabilities, diagnostics, and

‎rust/crates/core/src/lsp/interface/engine.rs‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ use std::sync::{Arc, Condvar, Mutex, MutexGuard, OnceLock};
3636
use std::thread;
3737
use std::time::{Duration, Instant};
3838

39-
const DEFAULT_INITIALIZE_TIMEOUT_MS: u64 = 10_000;
39+
// Cold language-server runtimes can spend more than ten seconds loading their
40+
// bundles before answering initialize. This remains one bounded handshake,
41+
// independent of request deadlines, with normal cancellation and disposal.
42+
const DEFAULT_INITIALIZE_TIMEOUT_MS: u64 = 60_000;
4043
const DEFAULT_REQUEST_TIMEOUT_MS: u64 = 30_000;
4144
const DEFAULT_SHUTDOWN_TIMEOUT_MS: u64 = 2_000;
4245
/// Upper bound of one build-provider request. A model request can load a
@@ -6233,6 +6236,28 @@ mod tests {
62336236
}
62346237
}
62356238

6239+
/// A real cold Windows language server can take longer than ten seconds.
6240+
/// Exercise the omitted-field default with an injected instant: it must
6241+
/// allow that handshake while still disposing of a server that never replies.
6242+
#[test]
6243+
fn default_initialize_budget_survives_cold_start_and_still_expires() {
6244+
let parsed: StartServerRequest = serde_json::from_value(json!({
6245+
"providerId": "cold-fixture", "executablePath": "/scripted-server",
6246+
"rootUri": "file:///workspace", "workingDirectory": "/workspace"
6247+
}))
6248+
.unwrap();
6249+
let harness = Harness::start(|request| {
6250+
request.initialize_timeout_milliseconds = parsed.initialize_timeout_milliseconds;
6251+
});
6252+
let session = harness.session();
6253+
let now = Instant::now();
6254+
session.expire_deadlines_at(now + Duration::from_secs(15));
6255+
assert_eq!(harness.snapshot().state, LspLifecycleState::Initializing);
6256+
session.expire_deadlines_at(now + Duration::from_secs(61));
6257+
assert_eq!(harness.snapshot().state, LspLifecycleState::Failed);
6258+
assert!(session.process.exit_status().is_some());
6259+
}
6260+
62366261
/// Criterion 1: a spawned process that never initializes cannot become ready.
62376262
#[test]
62386263
fn a_server_that_never_answers_initialize_fails_instead_of_becoming_ready() {

0 commit comments

Comments
 (0)