PM: merge M2.1 tree-sitter PHP syntax crate
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # docs/architecture.md
This commit is contained in:
commit
47eb357699
25 changed files with 1768 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Architecture
|
||||
|
||||
> **Status:** M0 decisions recorded, M1 workspace, desktop bridge, tabs and editor, message catalog, engine construction, settings, themes, the recovery journal, notifications, UI commands, the palette, the settings dialog and the app icon documented · **Last updated:** 2026-10-16
|
||||
> **Status:** M0 decisions recorded, M1 workspace, desktop bridge, tabs and editor, message catalog, engine construction, settings, themes, the recovery journal, notifications, UI commands, the palette, the settings dialog, the app icon and the syntax layer documented · **Last updated:** 2026-10-16
|
||||
|
||||
## Overview
|
||||
|
||||
|
|
@ -195,6 +195,18 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
|
|||
- **Keyboard:** Escape or a click outside closes; Tab and Shift+Tab wrap inside the dialog, focus that leaves it is pulled back to the search field, and focus returns to where it was on close.
|
||||
- No OK/Apply/Cancel: every change applies at once, as agents change settings through the same commands.
|
||||
|
||||
### Syntax (M2.1)
|
||||
|
||||
`crates/syntax` (L1, depends on `lutra-text` only) parses PHP with tree-sitter (`tree-sitter` 0.26, `tree-sitter-php` 0.25, both MIT; the grammar variant that accepts inline HTML around `<?php` tags). It has no engine types; M2.7 wires it to buffers and M2.5 builds the index on it.
|
||||
|
||||
- **API:** `Parser::new()?`, `parser.parse(&str) -> Tree` (never fails), `parser.reparse(&Tree, &[lutra_text::Edit]) -> Result<Tree, SyntaxError>`, `outline(&Tree) -> Vec<OutlineItem>`, `folding(&Tree) -> Vec<Range>`. `Tree` carries the text it was parsed from (a `lutra_text::Buffer`, cheap to clone) plus `truncated()` and `has_errors()`; that is why `outline` takes no separate text argument (the contract sketch had `outline(tree, text)`): a tree and a mismatching text can't be combined.
|
||||
- **Reparse:** the edit batch has `Buffer::apply` semantics (ranges against the old text, any order). It is mapped to one tree-sitter `InputEdit` covering the smallest start to the largest end, with points (row, byte column, rows by `\n` as tree-sitter counts them) computed from the old and new text. Proptests check that a reparse gives the same tree, outline and folding as a fresh parse whenever the edited text is error-free, and that an undo round trip ends at the original tree. On broken code tree-sitter's error recovery may legitimately differ between an incremental and a fresh parse; the engine can reparse from scratch when it wants a canonical tree (for example on save).
|
||||
- **Outline:** `OutlineItem {kind, name, detail, range, selection_range, children}`; `OutlineKind::as_str()` gives the contract names (`namespace`, `class`, …, `enumCase`). Braced and unbraced namespaces (an unbraced one owns everything up to the next namespace statement), promoted constructor parameters as properties after the constructor, enum cases with backing values, multi-element `const`/property declarations as one item each, attributes inside the declaration range. Anonymous classes are classes named `class@anonymous` (`OutlineItem::is_anonymous`, for the index to skip). Function, method and closure bodies are not searched; statements at file level are (`if (!function_exists(…)) { function … }`). Error nodes are transparent and nameless declarations are dropped. The search descends at most 96 levels.
|
||||
- **Folding:** multi-line brace blocks (class-like bodies, function and control bodies, `switch`/`match`), arrays, comments, heredoc/nowdoc, `use A\{…}` groups and runs of two or more `use` statements; ranges include the delimiters. The walk is iterative and skips the inside of single-line nodes.
|
||||
- **Positions:** 0-based line and UTF-16 column through `Buffer::offset_to_position` (about 1 µs per conversion on a 1 MB rope; the parse dominates).
|
||||
- **Limits:** texts over 8 MiB (`MAX_PARSE_BYTES`) are not parsed (`truncated`, empty outline and folding). The grammar's identifier rule covers the Basic Multilingual Plane only: PHP accepts any byte ≥ 0x80 in names, so an identifier with an emoji is an error node in tree-sitter.
|
||||
- **Timing** (release, Windows 11, MSVC `/O2`, generated 1 MB file, best of 5, other builds running in parallel, measured): full parse 364–553 ms, reparse after one inserted character 7–11 ms, outline 70–133 ms, folding 61–73 ms (143 ms before skipping single-line nodes). The full parse misses the 50 ms target by about 8×: tree-sitter-php runs at roughly 2–3 MB/s here. Consequences: parse off the engine lock and debounce (M2.7), parse files in parallel for the index (M2.5); `cargo test --release -p lutra-syntax --test perf -- --ignored --nocapture` repeats the measurement.
|
||||
|
||||
## Decisions (M0)
|
||||
|
||||
| Question | Decision | Why |
|
||||
|
|
@ -212,6 +224,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
|
|||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-16 | minor | M2.1: syntax layer (tree-sitter PHP parser, incremental reparse, outline, folding, size cap, timing) |
|
||||
| 2026-10-16 | minor | M1.15: modal rule (one modal at a time, restore dialog queued), `recoveryResolved` event |
|
||||
| 2026-10-16 | minor | M1.9b: settings dialog (store, search, controls by type, reset, live updates, font-size token override) |
|
||||
| 2026-10-16 | minor | M1.14: app icon from the owner's master, multi-size ICO, placeholder as fallback |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue