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

@ -3,9 +3,17 @@
//!
//! tree-sitter recovers from syntax errors heuristically, and the recovery
//! may differ between an incremental and a fresh parse of the same broken
//! text. Tree equality is therefore asserted whenever the edited text
//! parses without errors, and an undo round trip must always end at the
//! fresh tree of the (error-free) original.
//! text. Equality is therefore asserted whenever the edited text parses
//! without errors, and an undo round trip must always end at the fresh
//! result of the (error-free) original.
//!
//! Equality means the same outline, the same folding ranges and the same
//! sequence of leaf node kinds, not the same S-expression: an incremental
//! reparse may reuse a node where a fresh parse picks another wrapper for
//! the same tokens (tree-sitter-php 0.25.1 keeps `(union_type
//! (primitive_type))` for `array &$cache` after an undo, a fresh parse gives
//! `(primitive_type)`). Every structural feature Lutra builds on the tree
//! reads outline, folding or leaves, so wrapper nodes may differ.
#![allow(
clippy::unwrap_used,
@ -87,6 +95,18 @@ fn edit_for(text: &str, (start, len, fragment): (usize, usize, usize)) -> Edit {
Edit::replace(start..end.max(start), FRAGMENTS[fragment])
}
/// The kinds of the named leaf nodes of `tree`, in document order, read
/// from its S-expression: a leaf is a node that closes right after its kind.
fn leaf_kinds(tree: &lutra_syntax::Tree) -> Vec<String> {
let sexp = tree.to_sexp().replace('(', " ( ").replace(')', " ) ");
let tokens: Vec<&str> = sexp.split_whitespace().collect();
tokens
.windows(3)
.filter(|window| window[0] == "(" && window[2] == ")")
.map(|window| window[1].to_owned())
.collect()
}
proptest! {
#![proptest_config(ProptestConfig::with_cases(256))]
@ -134,7 +154,7 @@ proptest! {
let _ = outline(&tree);
let _ = folding(&tree);
if !fresh.has_errors() {
prop_assert_eq!(tree.to_sexp(), fresh.to_sexp());
prop_assert_eq!(leaf_kinds(&tree), leaf_kinds(&fresh));
prop_assert_eq!(outline(&tree), outline(&fresh));
prop_assert_eq!(folding(&tree), folding(&fresh));
}
@ -166,7 +186,7 @@ proptest! {
}
prop_assert_eq!(tree.text().text(), original);
if !expected.has_errors() {
prop_assert_eq!(tree.to_sexp(), expected.to_sexp());
prop_assert_eq!(leaf_kinds(&tree), leaf_kinds(&expected));
prop_assert_eq!(outline(&tree), outline(&expected));
prop_assert_eq!(folding(&tree), folding(&expected));
}