F3: suspended Phpactor start, ConPTY shell in a job, cancel superseded completions, syntax proptest
- lutra_proc::spawn_suspended: CREATE_SUSPENDED, join the kill-on-close job, resume via a Tool Help thread snapshot. Opt-in for long-lived children (Phpactor); git, php -l and the probe keep spawn because the snapshot costs ~60 ms per start. - lutra_proc::adopt + Guard (Windows): the terminal's ConPTY shell joins a job, so processes it started end with the tab or with Lutra. - lsp.completion cancels the previous pending completion on the same server ($/cancelRequest); the cancelled command resolves empty. - Syntax proptests compare leaf kinds, outline and folding instead of the S-expression (tree-sitter-php 0.25.1 keeps a union_type wrapper after an undo); Malte's seed added. - docs/development.md: data dirs, target dir inside the repo, parallel builds, deleting ui/node_modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7ad3005217
commit
ebbc89832c
17 changed files with 468 additions and 36 deletions
|
|
@ -19,6 +19,14 @@
|
|||
//! runs these commands through the `engine_execute_waiting` IPC, on a
|
||||
//! worker thread, so the window never waits either.
|
||||
//!
|
||||
//! **Superseded completions:** CodeMirror asks again as the user types and
|
||||
//! drops the older answer. Each new `lsp.completion` therefore cancels the
|
||||
//! previous one still pending on the same server (`$/cancelRequest`, via
|
||||
//! [`Server::cancel`]), so Phpactor stops computing a list nobody reads.
|
||||
//! The cancelled command resolves with the empty result, not an error.
|
||||
//! Hover and signature help are not cancelled: they are asked once per
|
||||
//! pause, not per keystroke.
|
||||
//!
|
||||
//! Without a session (no project, toolchain not ready, server failed) the
|
||||
//! commands fail with `failed`; a server that does not offer the feature,
|
||||
//! and a buffer that is not PHP, give the empty result. Server answers are
|
||||
|
|
@ -26,11 +34,12 @@
|
|||
//! empty result.
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::{Mutex, PoisonError};
|
||||
use std::time::Duration;
|
||||
|
||||
use lutra_lsp::types::position_to_json;
|
||||
use lutra_lsp::uri::path_to_uri;
|
||||
use lutra_lsp::{LspError, Range, Server};
|
||||
use lutra_lsp::{LspError, Range, RequestId, Server};
|
||||
use lutra_text::{ColumnUnit, Position};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Map, Value, json};
|
||||
|
|
@ -65,6 +74,13 @@ pub const REQUEST_TIMEOUT: Duration = Duration::from_secs(10);
|
|||
/// for the queue in front of it ([`Pending::wait`] adds one more second).
|
||||
const WAIT_TIMEOUT: Duration = Duration::from_secs(11);
|
||||
|
||||
/// The latest `textDocument/completion` request: the address of the
|
||||
/// [`Server`] it went to and its id. One slot for the process is enough:
|
||||
/// there is one PHP session per engine, and a slot taken over by another
|
||||
/// engine's server only means one older request runs to its end. The
|
||||
/// address keeps a request from being cancelled on another server.
|
||||
static LATEST_COMPLETION: Mutex<Option<(usize, RequestId)>> = Mutex::new(None);
|
||||
|
||||
/// Registers the commands of this module.
|
||||
///
|
||||
/// # Errors
|
||||
|
|
@ -146,6 +162,7 @@ impl Command for Completion {
|
|||
None => json!({"triggerKind": 1}),
|
||||
}),
|
||||
convert: completion_result,
|
||||
supersede: true,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -183,6 +200,7 @@ impl Command for Hover {
|
|||
empty: json!({ "contents": "" }),
|
||||
context: None,
|
||||
convert: hover_result,
|
||||
supersede: false,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -220,6 +238,7 @@ impl Command for SignatureHelp {
|
|||
empty: json!({ "signatures": [], "activeSignature": 0, "activeParameter": 0 }),
|
||||
context: None,
|
||||
convert: signature_result,
|
||||
supersede: false,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -243,6 +262,9 @@ struct Ask {
|
|||
context: Option<Value>,
|
||||
/// Converts the server's answer into the command's result.
|
||||
convert: fn(&Value) -> Value,
|
||||
/// Whether this request cancels the previous one of its kind still
|
||||
/// pending (completion; see the module docs).
|
||||
supersede: bool,
|
||||
}
|
||||
|
||||
/// Validates the request, queues it on the session (see the module docs)
|
||||
|
|
@ -262,6 +284,7 @@ fn ask(state: &mut State, ask: Ask) -> Result<Outcome, EngineError> {
|
|||
empty,
|
||||
context,
|
||||
convert,
|
||||
supersede,
|
||||
} = ask;
|
||||
let open = state
|
||||
.buffers
|
||||
|
|
@ -300,17 +323,28 @@ fn ask(state: &mut State, ask: Ask) -> Result<Outcome, EngineError> {
|
|||
let _ = sender.send(Ok(empty));
|
||||
return;
|
||||
}
|
||||
let empty = empty.clone();
|
||||
if supersede {
|
||||
cancel_latest(server);
|
||||
}
|
||||
let reply = sender.clone();
|
||||
let sent = server.request_with(
|
||||
method,
|
||||
request,
|
||||
REQUEST_TIMEOUT,
|
||||
Box::new(move |result: Result<Value, LspError>| {
|
||||
let _ = reply.send(result.map(|value| convert(&value)));
|
||||
let _ = reply.send(match result {
|
||||
Err(LspError::Cancelled) => Ok(empty),
|
||||
other => other.map(|value| convert(&value)),
|
||||
});
|
||||
}),
|
||||
);
|
||||
if let Err(e) = sent {
|
||||
let _ = sender.send(Err(e));
|
||||
match sent {
|
||||
Ok(request) if supersede => remember_latest(server, request),
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
let _ = sender.send(Err(e));
|
||||
}
|
||||
}
|
||||
});
|
||||
if !queued {
|
||||
|
|
@ -325,6 +359,33 @@ fn ask(state: &mut State, ask: Ask) -> Result<Outcome, EngineError> {
|
|||
)))
|
||||
}
|
||||
|
||||
/// The address that identifies `server` in [`LATEST_COMPLETION`].
|
||||
fn server_key(server: &Server) -> usize {
|
||||
std::ptr::from_ref(server).addr()
|
||||
}
|
||||
|
||||
/// Cancels the latest completion request if it went to `server` and is
|
||||
/// still pending; its command then resolves with the empty result. A
|
||||
/// poisoned slot is used as it is: it only holds plain data.
|
||||
fn cancel_latest(server: &Server) {
|
||||
let latest = LATEST_COMPLETION
|
||||
.lock()
|
||||
.unwrap_or_else(PoisonError::into_inner)
|
||||
.take();
|
||||
if let Some((key, id)) = latest
|
||||
&& key == server_key(server)
|
||||
{
|
||||
server.cancel(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Records `id` as the latest completion request, sent to `server`.
|
||||
fn remember_latest(server: &Server, id: RequestId) {
|
||||
*LATEST_COMPLETION
|
||||
.lock()
|
||||
.unwrap_or_else(PoisonError::into_inner) = Some((server_key(server), id));
|
||||
}
|
||||
|
||||
/// The command's value from the converted answer.
|
||||
///
|
||||
/// # Errors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue