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:
danny 2026-10-27 17:28:54 +01:00
parent 7ad3005217
commit ebbc89832c
17 changed files with 468 additions and 36 deletions

View file

@ -15,6 +15,9 @@ layer = 3
portable-pty = "0.9.0"
thiserror = "2.0.21"
[target.'cfg(windows)'.dependencies]
lutra-proc.workspace = true
[lints]
workspace = true

View file

@ -132,6 +132,10 @@ pub struct Session {
killer: Box<dyn ChildKiller + Send + Sync>,
/// Process id of the shell, if the platform reports one.
pid: Option<u32>,
/// The kill-on-close job the shell was adopted into (Windows), so the
/// shell and what it started die with the session or with Lutra.
#[cfg(windows)]
guard: lutra_proc::Guard,
}
impl std::fmt::Debug for Session {
@ -189,6 +193,15 @@ impl Session {
}
let mut child = pair.slave.spawn_command(cmd).map_err(spawn_error)?;
drop(pair.slave);
#[cfg(windows)]
let guard = match adopt(child.as_ref()) {
Ok(guard) => guard,
Err(e) => {
let _ = child.kill();
let _ = child.wait();
return Err(e);
}
};
let mut killer = child.clone_killer();
let pid = child.process_id();
let started = (|| {
@ -235,6 +248,8 @@ impl Session {
master,
killer,
pid,
#[cfg(windows)]
guard,
})
}
@ -344,7 +359,9 @@ impl Session {
}
/// Kills the shell unless it already exited, stops the reader and drops
/// buffered output. The pty closes once the waiter sees the exit.
/// buffered output. The pty closes once the waiter sees the exit. On
/// Windows it also kills every process left in the shell's job, such as
/// a background server the shell started, even after the shell exited.
/// Killing is best effort: an error means the process is already gone,
/// so it is ignored.
pub fn kill(&mut self) {
@ -360,9 +377,27 @@ impl Session {
if !exited {
let _ = self.killer.kill();
}
#[cfg(windows)]
self.guard.kill();
}
}
/// Adopts the ConPTY shell `child` into a kill-on-close job
/// ([`lutra_proc::adopt`]). The shell runs for a few microseconds before
/// that; a process it starts in that window is not in the job, and the
/// pseudo console still ends it when Lutra closes its pipes.
///
/// # Errors
/// [`TerminalError::Spawn`] when portable-pty gives no process handle or
/// the job cannot be set up.
#[cfg(windows)]
fn adopt(child: &dyn portable_pty::Child) -> Result<lutra_proc::Guard, TerminalError> {
let handle = child
.as_raw_handle()
.ok_or_else(|| TerminalError::Spawn("the shell has no process handle".into()))?;
lutra_proc::adopt(handle).map_err(spawn_error)
}
impl Drop for Session {
fn drop(&mut self) {
self.kill();