M2.1: tree-sitter PHP in crates/syntax

Parser (parse, incremental reparse from lutra_text edits), outline with
UTF-16 ranges and short signatures, folding ranges, 8 MiB parse cap.
Snapshot tests for five PHP 8.3 fixtures, proptests (random bytes,
reparse equals fresh parse, undo round trip), ignored release timing
test. Docs: architecture Syntax section, parity evidence, G4 note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-16 22:06:21 +02:00
parent d12a517009
commit a5236acd7e
25 changed files with 1768 additions and 6 deletions

44
Cargo.lock generated
View file

@ -2549,6 +2549,12 @@ version = "0.0.0"
[[package]]
name = "lutra-syntax"
version = "0.0.0"
dependencies = [
"lutra-text",
"proptest",
"tree-sitter",
"tree-sitter-php",
]
[[package]]
name = "lutra-terminal"
@ -3925,6 +3931,8 @@ version = "1.0.154"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
dependencies = [
"foldhash",
"indexmap 2.14.2",
"itoa",
"memchr",
"serde",
@ -4152,6 +4160,12 @@ version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d08889ec5408683408db66ad89e0e1f93dff55c73a4ccc71c427d5b277ee47e6"
[[package]]
name = "streaming-iterator"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520"
[[package]]
name = "string_cache"
version = "0.9.0"
@ -4958,6 +4972,36 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "tree-sitter"
version = "0.26.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17ebdd3a5a7e28a1890b876fdbd0c3c0fe0a6336cffaa104f11b9f720c9daa29"
dependencies = [
"cc",
"regex",
"regex-syntax",
"serde_json",
"streaming-iterator",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-language"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "009994f150cc0cd50ff54917d5bc8bffe8cad10ca10d81c34da2ec421ae61782"
[[package]]
name = "tree-sitter-php"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9779e392d38af4254f48be0e57b7eed4d50ec7a6e55a7e5e2e74df8f8f032d3"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]]
name = "try-lock"
version = "0.2.5"

View file

@ -28,6 +28,8 @@ proptest = "1.12.0"
ignore = "0.4.33"
notify = "8.2.0"
tempfile = "3.27.0"
tree-sitter = "0.26.13"
tree-sitter-php = "0.25.1"
[workspace.lints.rust]
missing_docs = "deny"

View file

@ -12,6 +12,12 @@ publish.workspace = true
layer = 1
[dependencies]
lutra-text.workspace = true
tree-sitter.workspace = true
tree-sitter-php.workspace = true
[dev-dependencies]
proptest.workspace = true
[lints]
workspace = true

View file

@ -0,0 +1,112 @@
//! Folding ranges of a PHP file.
//!
//! A region folds when it spans at least two lines. Foldable regions are
//! blocks in braces (class, interface, trait and enum bodies, function and
//! method bodies, control-flow blocks, `switch` and `match` bodies), array
//! literals, comments, heredoc and nowdoc strings, grouped `use` imports
//! (`use A\{B, C}`) and runs of two or more consecutive `use` statements.
//!
//! Ranges cover the whole region, delimiters included (`{` to `}`, `/*` to
//! `*/`); the editor decides which part stays visible when folded.
use tree_sitter::{Language, Node};
use crate::{Range, Tree};
/// Node kinds that fold as a whole.
const FOLDABLE: &[&str] = &[
"compound_statement",
"declaration_list",
"enum_declaration_list",
"switch_block",
"match_block",
"array_creation_expression",
"comment",
"heredoc",
"nowdoc",
"namespace_use_group",
];
/// The folding ranges of `tree`, sorted by start, without duplicates.
///
/// Empty for a [`Tree::truncated`] tree. Error nodes never fold, but
/// regions inside them do. The walk is iterative, so deeply nested input
/// cannot exhaust the stack, and it skips the inside of single-line nodes,
/// which cannot contain a multi-line region.
pub fn folding(tree: &Tree) -> Vec<Range> {
let Some(root) = tree.root() else {
return Vec::new();
};
let language: Language = tree_sitter_php::LANGUAGE_PHP.into();
let foldable: Vec<u16> = FOLDABLE
.iter()
.map(|kind| language.id_for_node_kind(kind, true))
.collect();
let use_parents = [
language.id_for_node_kind("program", true),
language.id_for_node_kind("compound_statement", true),
];
let mut bytes = Vec::new();
let mut cursor = root.walk();
'walk: loop {
let node = cursor.node();
if node.end_position().row > node.start_position().row {
let kind = node.kind_id();
if foldable.contains(&kind) && !node.is_error() {
bytes.push((node.start_byte(), node.end_byte()));
}
if use_parents.contains(&kind) {
use_runs(&mut bytes, node);
}
if cursor.goto_first_child() {
continue;
}
}
while !cursor.goto_next_sibling() {
if !cursor.goto_parent() {
break 'walk;
}
}
}
let mut ranges: Vec<Range> = bytes
.into_iter()
.filter_map(|(start, end)| Range::from_bytes(tree.text(), start, end))
.collect();
ranges.sort();
ranges.dedup();
ranges
}
/// Adds the runs of two or more consecutive `use` statements among the
/// children of `node`.
fn use_runs(bytes: &mut Vec<(usize, usize)>, node: Node<'_>) {
let mut cursor = node.walk();
let mut run: Option<(Node<'_>, Node<'_>)> = None;
for child in node.named_children(&mut cursor) {
if child.kind() == "namespace_use_declaration" {
run = Some(match run {
Some((first, _)) => (first, child),
None => (child, child),
});
continue;
}
if let Some((first, last)) = run.take()
&& first.id() != last.id()
{
push_multiline(bytes, first, last);
}
}
if let Some((first, last)) = run
&& first.id() != last.id()
{
push_multiline(bytes, first, last);
}
}
/// Adds the byte range from the start of `first` to the end of `last` when
/// it spans more than one line.
fn push_multiline(bytes: &mut Vec<(usize, usize)>, first: Node<'_>, last: Node<'_>) {
if last.end_position().row > first.start_position().row {
bytes.push((first.start_byte(), last.end_byte()));
}
}

View file

@ -1,4 +1,24 @@
//! Syntax layer for Lutra (layer L1).
//!
//! Parses source files with tree-sitter (PHP first) and derives outlines,
//! folding ranges and highlight tokens from the syntax tree.
//! Parses PHP source with tree-sitter and derives the structure the rest of
//! the IDE builds on: the outline (namespaces, classes, functions, members)
//! and folding ranges. Highlighting in the editor is done by CodeMirror's
//! Lezer grammar in the UI; this crate is the structural source for the
//! outline, folding and the symbol index (see `docs/architecture.md`).
//!
//! Source text is untrusted: nothing here panics on broken PHP or random
//! bytes. Files over [`MAX_PARSE_BYTES`] are not parsed; their [`Tree`]
//! reports [`Tree::truncated`] and yields an empty outline.
//!
//! Positions are zero-based lines and columns counted in UTF-16 code units,
//! converted through `lutra_text`.
mod folding;
mod outline;
mod parser;
mod range;
pub use folding::folding;
pub use outline::{ANONYMOUS_CLASS_NAME, OutlineItem, OutlineKind, outline};
pub use parser::{MAX_PARSE_BYTES, Parser, SyntaxError, Tree};
pub use range::Range;

View file

@ -0,0 +1,531 @@
//! The structural outline of a PHP file.
//!
//! The outline lists namespaces, classes, interfaces, traits, enums,
//! functions and their members (methods, properties, constants, enum
//! cases) as a tree in source order. It feeds the Structure tool window
//! and the symbol index.
//!
//! - Braced namespaces (`namespace A { … }`) contain their declarations;
//! an unbraced `namespace A;` contains every declaration up to the next
//! namespace statement. The global `namespace { … }` adds no item.
//! - Constructor-promoted parameters become properties of their class,
//! listed right after the constructor.
//! - Anonymous classes appear as classes named [`ANONYMOUS_CLASS_NAME`]
//! (PHP's own name for them); indexers skip them with
//! [`OutlineItem::is_anonymous`].
//! - Function, method and closure bodies are not searched, so local
//! closures and classes inside them are not listed. Declarations nested
//! in top-level statements (`if (!function_exists(…)) { function … }`)
//! are.
//! - Error nodes are transparent: their content is searched, but they never
//! become items, and declarations without a name are skipped.
use lutra_text::Buffer;
use tree_sitter::Node;
use crate::{Range, Tree};
/// The name given to anonymous classes (`new class { … }`), as PHP itself
/// reports them.
pub const ANONYMOUS_CLASS_NAME: &str = "class@anonymous";
/// How deep the outline search descends through statements and
/// expressions. Deeper nesting is not searched, which bounds recursion on
/// adversarial input.
const MAX_DEPTH: usize = 96;
/// Longest `detail` string, in chars; longer signatures end in `…`.
const MAX_DETAIL_CHARS: usize = 160;
/// What an outline item declares.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum OutlineKind {
/// `namespace A\B;` or `namespace A\B { … }`.
Namespace,
/// A class, named or anonymous.
Class,
/// An interface.
Interface,
/// A trait.
Trait,
/// An enum.
Enum,
/// A function declared outside a class.
Function,
/// A method of a class, interface, trait or enum.
Method,
/// A property, declared or constructor-promoted.
Property,
/// A class constant or a `const` outside a class.
Constant,
/// A `case` of an enum.
EnumCase,
}
impl OutlineKind {
/// The kind's name as the engine and the UI use it: `namespace`,
/// `class`, `interface`, `trait`, `enum`, `function`, `method`,
/// `property`, `constant` or `enumCase`.
pub fn as_str(self) -> &'static str {
match self {
Self::Namespace => "namespace",
Self::Class => "class",
Self::Interface => "interface",
Self::Trait => "trait",
Self::Enum => "enum",
Self::Function => "function",
Self::Method => "method",
Self::Property => "property",
Self::Constant => "constant",
Self::EnumCase => "enumCase",
}
}
}
/// One declaration in the outline.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OutlineItem {
/// What the item declares.
pub kind: OutlineKind,
/// The declared name as written: `App\Models` for a namespace, `$id`
/// for a property (with the `$`), [`ANONYMOUS_CLASS_NAME`] for an
/// anonymous class.
pub name: String,
/// A short signature with whitespace collapsed, capped at 160 chars:
/// - functions and methods: `(int $id, string ...$tags): ?Product`
/// (types, `&`, `...` and names; no defaults or attributes);
/// - classes: `extends Base implements A, B`; interfaces: `extends A`;
/// enums: `: string implements HasLabel`;
/// - properties and typed constants: the type, e.g. `?string`;
/// - enum cases: the backing value, e.g. `'draft'`.
///
/// `None` when there is nothing to show.
pub detail: Option<String>,
/// The whole declaration, attributes and modifiers included.
pub range: Range,
/// The name inside the declaration, to select or reveal.
pub selection_range: Range,
/// Nested declarations in source order.
pub children: Vec<OutlineItem>,
}
impl OutlineItem {
/// Whether the item is an anonymous class.
pub fn is_anonymous(&self) -> bool {
self.kind == OutlineKind::Class && self.name == ANONYMOUS_CLASS_NAME
}
}
/// The outline of `tree`, top-level items in source order.
///
/// Empty for a [`Tree::truncated`] tree. Never fails: broken code yields
/// the items that could still be recognised.
pub fn outline(tree: &Tree) -> Vec<OutlineItem> {
let Some(root) = tree.root() else {
return Vec::new();
};
let source = tree.text().text();
let builder = Builder {
source: &source,
text: tree.text(),
};
let mut items = Vec::new();
builder.collect(root, 0, &mut items);
items
}
/// Walks the syntax tree and builds outline items.
struct Builder<'a> {
/// The parsed text, for names and signatures.
source: &'a str,
/// The same text as a buffer, for UTF-16 positions.
text: &'a Buffer,
}
impl Builder<'_> {
/// Adds the items found among the named children of `node` to `out`,
/// grouping declarations after an unbraced namespace into it.
fn collect(&self, node: Node<'_>, depth: usize, out: &mut Vec<OutlineItem>) {
if depth > MAX_DEPTH {
return;
}
let mut cursor = node.walk();
let children: Vec<Node<'_>> = node.named_children(&mut cursor).collect();
let mut children = children.into_iter().peekable();
while let Some(child) = children.next() {
if child.kind() != "namespace_definition" || child.child_by_field_name("body").is_some()
{
self.item(child, depth, out);
continue;
}
let mut members = Vec::new();
let mut end = child.end_byte();
while let Some(next) = children.next_if(|next| next.kind() != "namespace_definition") {
end = next.end_byte();
self.item(next, depth.saturating_add(1), &mut members);
}
match self.named(
child,
"name",
OutlineKind::Namespace,
None,
child.start_byte(),
end,
) {
Some(mut namespace) => {
namespace.children = members;
out.push(namespace);
}
None => out.append(&mut members),
}
}
}
/// Adds the item(s) declared by `node` to `out`, or searches inside it
/// when it declares nothing itself.
fn item(&self, node: Node<'_>, depth: usize, out: &mut Vec<OutlineItem>) {
let next = depth.saturating_add(1);
match node.kind() {
"namespace_definition" => self.braced_namespace(node, next, out),
"class_declaration" => self.class_like(node, OutlineKind::Class, next, out),
"interface_declaration" => self.class_like(node, OutlineKind::Interface, next, out),
"trait_declaration" => self.class_like(node, OutlineKind::Trait, next, out),
"enum_declaration" => self.class_like(node, OutlineKind::Enum, next, out),
"anonymous_class" => self.anonymous_class(node, next, out),
"function_definition" => {
let detail = self.signature(node);
out.extend(self.whole(node, OutlineKind::Function, detail));
}
"method_declaration" => self.method(node, out),
"property_declaration" => self.properties(node, out),
"const_declaration" => self.constants(node, out),
"enum_case" => {
let detail = self.field_text(node, "value");
out.extend(self.whole(node, OutlineKind::EnumCase, detail));
}
"anonymous_function" | "arrow_function" | "comment" | "text" | "php_tag" => {}
_ => self.collect(node, next, out),
}
}
/// A braced namespace with its declarations; the global `namespace {}`
/// adds its declarations directly.
fn braced_namespace(&self, node: Node<'_>, depth: usize, out: &mut Vec<OutlineItem>) {
let mut members = Vec::new();
if let Some(body) = node.child_by_field_name("body") {
self.collect(body, depth, &mut members);
}
let item = self.named(
node,
"name",
OutlineKind::Namespace,
None,
node.start_byte(),
node.end_byte(),
);
match item {
Some(mut namespace) => {
namespace.children = members;
out.push(namespace);
}
None => out.append(&mut members),
}
}
/// A class, interface, trait or enum with its members.
fn class_like(
&self,
node: Node<'_>,
kind: OutlineKind,
depth: usize,
out: &mut Vec<OutlineItem>,
) {
let Some(mut item) = self.whole(node, kind, self.heritage(node)) else {
return;
};
if let Some(body) = node.child_by_field_name("body") {
self.collect(body, depth, &mut item.children);
}
out.push(item);
}
/// An anonymous class, selected at its `class` keyword.
fn anonymous_class(&self, node: Node<'_>, depth: usize, out: &mut Vec<OutlineItem>) {
let mut cursor = node.walk();
let keyword = node
.children(&mut cursor)
.find(|child| child.kind() == "class");
let (Some(range), Some(selection_range)) = (
self.range(node.start_byte(), node.end_byte()),
keyword.and_then(|keyword| self.range(keyword.start_byte(), keyword.end_byte())),
) else {
return;
};
let mut item = OutlineItem {
kind: OutlineKind::Class,
name: ANONYMOUS_CLASS_NAME.to_owned(),
detail: self.heritage(node),
range,
selection_range,
children: Vec::new(),
};
if let Some(body) = node.child_by_field_name("body") {
self.collect(body, depth, &mut item.children);
}
out.push(item);
}
/// A method, followed by the properties its parameters promote when it
/// is the constructor.
fn method(&self, node: Node<'_>, out: &mut Vec<OutlineItem>) {
let Some(method) = self.whole(node, OutlineKind::Method, self.signature(node)) else {
return;
};
let is_constructor = method.name.eq_ignore_ascii_case("__construct");
out.push(method);
if !is_constructor {
return;
}
let Some(parameters) = node.child_by_field_name("parameters") else {
return;
};
let mut cursor = parameters.walk();
for parameter in parameters.named_children(&mut cursor) {
if parameter.kind() != "property_promotion_parameter" {
continue;
}
let Some(mut name) = parameter.child_by_field_name("name") else {
continue;
};
if name.kind() == "by_ref" {
let mut inner = name.walk();
let Some(variable) = name
.named_children(&mut inner)
.find(|child| child.kind() == "variable_name")
else {
continue;
};
name = variable;
}
let detail = self.field_text(parameter, "type");
out.extend(self.item_at(
OutlineKind::Property,
name,
detail,
parameter.start_byte(),
parameter.end_byte(),
));
}
}
/// One property item per element of a property declaration
/// (`public int $a, $b;` gives two).
fn properties(&self, node: Node<'_>, out: &mut Vec<OutlineItem>) {
let detail = self.field_text(node, "type");
let mut cursor = node.walk();
let elements: Vec<Node<'_>> = node
.named_children(&mut cursor)
.filter(|child| child.kind() == "property_element")
.collect();
let single = elements.len() == 1;
for element in elements {
let outer = if single { node } else { element };
out.extend(self.named(
element,
"name",
OutlineKind::Property,
detail.clone(),
outer.start_byte(),
outer.end_byte(),
));
}
}
/// One constant item per element of a `const` declaration.
fn constants(&self, node: Node<'_>, out: &mut Vec<OutlineItem>) {
let detail = self.field_text(node, "type");
let mut cursor = node.walk();
let elements: Vec<Node<'_>> = node
.named_children(&mut cursor)
.filter(|child| child.kind() == "const_element")
.collect();
let single = elements.len() == 1;
for element in elements {
let mut inner = element.walk();
let Some(name) = element
.named_children(&mut inner)
.find(|child| child.kind() == "name")
else {
continue;
};
let outer = if single { node } else { element };
out.extend(self.item_at(
OutlineKind::Constant,
name,
detail.clone(),
outer.start_byte(),
outer.end_byte(),
));
}
}
/// An item spanning `node`, named by its `name` field.
fn whole(
&self,
node: Node<'_>,
kind: OutlineKind,
detail: Option<String>,
) -> Option<OutlineItem> {
self.named(
node,
"name",
kind,
detail,
node.start_byte(),
node.end_byte(),
)
}
/// An item spanning bytes `start..end`, named by the `field` child of
/// `node`.
fn named(
&self,
node: Node<'_>,
field: &str,
kind: OutlineKind,
detail: Option<String>,
start: usize,
end: usize,
) -> Option<OutlineItem> {
let name = node.child_by_field_name(field)?;
self.item_at(kind, name, detail, start, end)
}
/// An item spanning bytes `start..end` whose name is the text of
/// `name`. `None` when the name is missing, empty or an error node.
fn item_at(
&self,
kind: OutlineKind,
name: Node<'_>,
detail: Option<String>,
start: usize,
end: usize,
) -> Option<OutlineItem> {
if name.is_missing() || name.is_error() {
return None;
}
let text: String = self.text_of(name)?.split_whitespace().collect();
if text.is_empty() {
return None;
}
Some(OutlineItem {
kind,
name: text,
detail,
range: self.range(start, end)?,
selection_range: self.range(name.start_byte(), name.end_byte())?,
children: Vec::new(),
})
}
/// The parameter list and return type of a function or method, e.g.
/// `(int $id, string &...$tags): ?Product`.
fn signature(&self, node: Node<'_>) -> Option<String> {
let mut signature = String::from("(");
if let Some(parameters) = node.child_by_field_name("parameters") {
let mut cursor = parameters.walk();
let rendered: Vec<String> = parameters
.named_children(&mut cursor)
.filter_map(|parameter| self.parameter(parameter))
.collect();
signature.push_str(&rendered.join(", "));
}
signature.push(')');
if let Some(returns) = self.field_text(node, "return_type") {
signature.push_str(": ");
signature.push_str(&returns);
}
Some(cap(signature))
}
/// One parameter as `type &...$name`; `None` for anything that is not
/// a parameter (comments, error nodes).
fn parameter(&self, node: Node<'_>) -> Option<String> {
let variadic = match node.kind() {
"simple_parameter" | "property_promotion_parameter" => false,
"variadic_parameter" => true,
_ => return None,
};
let mut rendered = String::new();
if let Some(kind) = self.field_text(node, "type") {
rendered.push_str(&kind);
rendered.push(' ');
}
if node.child_by_field_name("reference_modifier").is_some() {
rendered.push('&');
}
if variadic {
rendered.push_str("...");
}
let name: String = self
.text_of(node.child_by_field_name("name")?)?
.split_whitespace()
.collect();
rendered.push_str(&name);
Some(rendered)
}
/// `extends …` / `implements …` of a class-like declaration, and the
/// backing type of an enum.
fn heritage(&self, node: Node<'_>) -> Option<String> {
let mut cursor = node.walk();
let mut parts = Vec::new();
for child in node.named_children(&mut cursor) {
match child.kind() {
"primitive_type" => parts.push(format!(": {}", collapse(self.text_of(child)?))),
"base_clause" | "class_interface_clause" => {
parts.push(collapse(self.text_of(child)?))
}
_ => {}
}
}
(!parts.is_empty()).then(|| cap(parts.join(" ")))
}
/// The whitespace-collapsed, capped text of the `field` child of
/// `node`.
fn field_text(&self, node: Node<'_>, field: &str) -> Option<String> {
let child = node.child_by_field_name(field)?;
let text = collapse(self.text_of(child)?);
(!text.is_empty()).then(|| cap(text))
}
/// The source text of `node`.
fn text_of(&self, node: Node<'_>) -> Option<&str> {
self.source.get(node.byte_range())
}
/// The UTF-16 range of bytes `start..end`.
fn range(&self, start: usize, end: usize) -> Option<Range> {
Range::from_bytes(self.text, start, end)
}
}
/// `text` with every run of whitespace replaced by one space and the ends
/// trimmed.
fn collapse(text: &str) -> String {
text.split_whitespace().collect::<Vec<_>>().join(" ")
}
/// `text` cut to [`MAX_DETAIL_CHARS`] chars, ending in `…` when cut.
fn cap(text: String) -> String {
if text.chars().count() <= MAX_DETAIL_CHARS {
return text;
}
let mut capped: String = text
.chars()
.take(MAX_DETAIL_CHARS.saturating_sub(1))
.collect();
capped.push('…');
capped
}

273
crates/syntax/src/parser.rs Normal file
View file

@ -0,0 +1,273 @@
//! The PHP parser and its syntax tree.
//!
//! [`Parser`] wraps a tree-sitter parser loaded with the PHP grammar
//! (`tree-sitter-php`, the variant that accepts inline HTML around
//! `<?php` tags, as `.php` files do). [`Tree`] keeps the text it was parsed
//! from, so an incremental [`Parser::reparse`] needs only the edits.
use std::fmt;
use lutra_text::{Buffer, Edit, TextError};
use tree_sitter::{InputEdit, Node, Point};
/// Files larger than this many bytes (8 MiB) are not parsed.
///
/// A [`Tree`] for such a text reports [`Tree::truncated`], has no syntax
/// nodes and yields an empty outline and no folding ranges.
pub const MAX_PARSE_BYTES: usize = 8 * 1024 * 1024;
/// Errors of the syntax layer.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SyntaxError {
/// The PHP grammar could not be loaded into tree-sitter, for example
/// because its ABI version is not supported by the linked library.
Language(String),
/// An edit passed to [`Parser::reparse`] was rejected by `lutra_text`
/// (reversed, out of range, not on a character boundary, overlapping).
Edit(TextError),
}
impl fmt::Display for SyntaxError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Language(reason) => write!(f, "cannot load the PHP grammar: {reason}"),
Self::Edit(error) => write!(f, "invalid edit: {error}"),
}
}
}
impl std::error::Error for SyntaxError {}
impl From<TextError> for SyntaxError {
fn from(error: TextError) -> Self {
Self::Edit(error)
}
}
/// A parsed PHP text.
///
/// Holds the tree-sitter tree together with the text it was parsed from.
/// Cloning is cheap: the text is a rope and tree-sitter trees are
/// reference counted. Broken PHP still produces a tree; tree-sitter marks
/// the broken parts as error nodes, which the outline and folding skip.
#[derive(Debug, Clone)]
pub struct Tree {
/// The syntax tree; `None` when the text was too large to parse or
/// tree-sitter gave up.
inner: Option<tree_sitter::Tree>,
/// The text the tree describes.
text: Buffer,
/// Whether parsing was skipped because the text exceeds
/// [`MAX_PARSE_BYTES`].
truncated: bool,
}
impl Tree {
/// The text this tree was parsed from.
pub fn text(&self) -> &Buffer {
&self.text
}
/// Whether the text was too large to parse (over [`MAX_PARSE_BYTES`]).
///
/// The engine reports this as `truncated` next to the outline.
pub fn truncated(&self) -> bool {
self.truncated
}
/// Whether the tree contains syntax errors or missing tokens.
pub fn has_errors(&self) -> bool {
self.root().is_some_and(|root| root.has_error())
}
/// The tree in tree-sitter's S-expression notation, without positions.
///
/// Meant for tests and diagnostics; empty when nothing was parsed.
pub fn to_sexp(&self) -> String {
self.root().map(|root| root.to_sexp()).unwrap_or_default()
}
/// The root node, if the text was parsed.
pub(crate) fn root(&self) -> Option<Node<'_>> {
self.inner.as_ref().map(tree_sitter::Tree::root_node)
}
}
/// A PHP parser.
///
/// Reuse one parser for many parses; it is cheap to keep but not to
/// create. A parser is `Send` but parses one text at a time (`&mut self`).
pub struct Parser {
/// The tree-sitter parser with the PHP grammar loaded.
inner: tree_sitter::Parser,
}
impl fmt::Debug for Parser {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Parser").finish_non_exhaustive()
}
}
impl Parser {
/// Creates a parser for PHP files (inline HTML allowed around
/// `<?php … ?>`).
///
/// # Errors
/// Fails with [`SyntaxError::Language`] when the bundled grammar cannot
/// be loaded, which only happens with a mismatched tree-sitter build.
pub fn new() -> Result<Self, SyntaxError> {
let mut inner = tree_sitter::Parser::new();
inner
.set_language(&tree_sitter_php::LANGUAGE_PHP.into())
.map_err(|error| SyntaxError::Language(error.to_string()))?;
Ok(Self { inner })
}
/// Parses `text` from scratch.
///
/// Never fails: broken PHP yields a tree with error nodes, and a text
/// over [`MAX_PARSE_BYTES`] yields an empty, [`Tree::truncated`] tree.
pub fn parse(&mut self, text: &str) -> Tree {
self.parse_buffer(Buffer::new(text), text, None)
}
/// Applies `edits` to the text of `tree` and parses the result
/// incrementally, reusing the unchanged parts of `tree`.
///
/// `edits` follow [`Buffer::apply`]: every range refers to the text of
/// `tree` (before any of the edits), in any order. The batch is mapped
/// to one tree-sitter edit that covers all changed bytes, with
/// positions computed from the old and new text. The result equals a
/// fresh [`Parser::parse`] of the edited text.
///
/// # Errors
/// Fails with [`SyntaxError::Edit`] when `lutra_text` rejects the
/// batch; `tree` is unaffected.
pub fn reparse(&mut self, tree: &Tree, edits: &[Edit]) -> Result<Tree, SyntaxError> {
let mut buffer = tree.text.clone();
buffer.apply(edits)?;
let new_text = buffer.text();
let (Some(old_tree), Some(input_edit)) = (
tree.inner.as_ref(),
covering_edit(&tree.text.text(), &new_text, edits),
) else {
return Ok(self.parse_buffer(buffer, &new_text, None));
};
let mut edited = old_tree.clone();
edited.edit(&input_edit);
Ok(self.parse_buffer(buffer, &new_text, Some(&edited)))
}
/// Parses `text` (the contents of `buffer`), reusing `old` when given.
fn parse_buffer(
&mut self,
buffer: Buffer,
text: &str,
old: Option<&tree_sitter::Tree>,
) -> Tree {
if text.len() > MAX_PARSE_BYTES {
return Tree {
inner: None,
text: buffer,
truncated: true,
};
}
Tree {
inner: self.inner.parse(text, old),
text: buffer,
truncated: false,
}
}
}
/// Builds the single tree-sitter edit that turns `old` into `new` for a
/// batch of `edits` that `lutra_text` already accepted against `old`.
///
/// The edit spans from the smallest start to the largest end of the batch,
/// which keeps it correct however the batch orders insertions that share
/// an offset. Returns `None` for an empty batch or inconsistent lengths, in
/// which case the caller parses from scratch.
fn covering_edit(old: &str, new: &str, edits: &[Edit]) -> Option<InputEdit> {
let start_byte = edits.iter().map(|edit| edit.range.start).min()?;
let old_end_byte = edits.iter().map(|edit| edit.range.end).max()?;
let new_end_byte = old_end_byte
.checked_add(new.len())?
.checked_sub(old.len())?;
if new_end_byte < start_byte {
return None;
}
Some(InputEdit {
start_byte,
old_end_byte,
new_end_byte,
start_position: point_at(old, start_byte),
old_end_position: point_at(old, old_end_byte),
new_end_position: point_at(new, new_end_byte),
})
}
/// The tree-sitter point (row, byte column) of byte `offset` in `text`.
///
/// tree-sitter counts rows by `\n` only. An offset past the end is clamped
/// to the end of the text.
fn point_at(text: &str, offset: usize) -> Point {
let bytes = text.as_bytes();
let prefix = bytes.get(..offset).unwrap_or(bytes);
let row = prefix.iter().filter(|byte| **byte == b'\n').count();
let line_start = prefix
.iter()
.rposition(|byte| *byte == b'\n')
.map_or(0, |newline| newline.saturating_add(1));
Point {
row,
column: prefix.len().saturating_sub(line_start),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn point_counts_rows_and_byte_columns() {
let text = "ab\ncä\n";
assert_eq!(point_at(text, 0), Point { row: 0, column: 0 });
assert_eq!(point_at(text, 3), Point { row: 1, column: 0 });
assert_eq!(point_at(text, 6), Point { row: 1, column: 3 });
assert_eq!(point_at(text, 7), Point { row: 2, column: 0 });
assert_eq!(point_at(text, 99), Point { row: 2, column: 0 });
}
#[test]
fn oversized_text_is_not_parsed() {
let mut parser = Parser::new().unwrap();
let text = format!("<?php\n/*{}*/", "x".repeat(MAX_PARSE_BYTES));
let tree = parser.parse(&text);
assert!(tree.truncated());
assert!(tree.to_sexp().is_empty());
let shrunk = parser
.reparse(&tree, &[Edit::delete(8..MAX_PARSE_BYTES)])
.unwrap();
assert!(!shrunk.truncated());
assert_eq!(
shrunk.to_sexp(),
parser.parse("<?php\n/*xxxxxxxx*/").to_sexp()
);
}
#[test]
fn rejected_edit_is_an_error() {
let mut parser = Parser::new().unwrap();
let tree = parser.parse("<?php echo 1;");
let error = parser.reparse(&tree, &[Edit::delete(5..99)]).unwrap_err();
assert!(matches!(error, SyntaxError::Edit(_)));
}
#[test]
fn empty_batch_reparses_to_the_same_tree() {
let mut parser = Parser::new().unwrap();
let tree = parser.parse("<?php function f() {}");
let again = parser.reparse(&tree, &[]).unwrap();
assert_eq!(again.to_sexp(), tree.to_sexp());
}
}

View file

@ -0,0 +1,28 @@
//! Ranges in line and UTF-16 column coordinates.
use lutra_text::{Buffer, ColumnUnit, Position};
/// A range between two positions, end exclusive.
///
/// Lines and columns are zero-based; columns count UTF-16 code units, as
/// CodeMirror and LSP do.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Range {
/// First position inside the range.
pub start: Position,
/// Position just after the range.
pub end: Position,
}
impl Range {
/// Converts the byte range `start..end` of `text` into a [`Range`].
///
/// Returns `None` when either offset is past the end of the text, inside
/// a character or inside a CRLF line break.
pub(crate) fn from_bytes(text: &Buffer, start: usize, end: usize) -> Option<Self> {
Some(Self {
start: text.offset_to_position(start, ColumnUnit::Utf16).ok()?,
end: text.offset_to_position(end, ColumnUnit::Utf16).ok()?,
})
}
}

View file

@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace Shop\Catalog {
use Shop\Money\Price;
interface Sellable extends \Stringable, \Countable
{
public const string CURRENCY = 'EUR';
public function price(): Price;
}
final class Product implements Sellable
{
private array $tags = [], $notes = [];
public function __construct(
public readonly int $id,
protected ?string $title = null,
private array &$cache = [],
string $unused = '',
) {
}
public function find(int $id): ?Product
{
return $id === $this->id ? $this : null;
}
public static function tagged(string ...$tags): static
{
return new static(0);
}
public function price(): Price
{
return new Price(0);
}
public function __toString(): string
{
return (string) $this->title;
}
public function count(): int
{
return \count($this->tags);
}
}
}
namespace Shop\Orders {
function total(array $lines, float $vat = 0.19): float
{
return array_sum($lines) * (1 + $vat);
}
const MAX_LINES = 100, MIN_LINES = 1;
}
namespace {
function bootstrap(): void
{
}
}

View file

@ -0,0 +1,36 @@
# outline
namespace Shop\Catalog @4:0-51:1 sel 4:10-4:22
interface Sellable extends \Stringable, \Countable @7:4-12:5 sel 7:14-7:22
constant CURRENCY string @9:8-9:45 sel 9:28-9:36
method price (): Price @11:8-11:39 sel 11:24-11:29
class Product implements Sellable @14:4-50:5 sel 14:16-14:23
property $tags array @16:22-16:32 sel 16:22-16:27
property $notes array @16:34-16:45 sel 16:34-16:40
method __construct (int $id, ?string $title, array &$cache, string $unused) @18:8-24:9 sel 18:24-18:35
property $id int @19:12-19:35 sel 19:32-19:35
property $title ?string @20:12-20:43 sel 20:30-20:36
property $cache array @21:12-21:38 sel 21:27-21:33
method find (int $id): ?Product @26:8-29:9 sel 26:24-26:28
method tagged (string ...$tags): static @31:8-34:9 sel 31:31-31:37
method price (): Price @36:8-39:9 sel 36:24-36:29
method __toString (): string @41:8-44:9 sel 41:24-41:34
method count (): int @46:8-49:9 sel 46:24-46:29
namespace Shop\Orders @53:0-60:1 sel 53:10-53:21
function total (array $lines, float $vat): float @54:4-57:5 sel 54:13-54:18
constant MAX_LINES @59:10-59:25 sel 59:10-59:19
constant MIN_LINES @59:27-59:40 sel 59:27-59:36
function bootstrap (): void @63:4-65:5 sel 63:13-63:22
# folding
4:23-51:1
8:4-12:5
15:4-50:5
23:10-24:9
27:8-29:9
32:8-34:9
37:8-39:9
42:8-44:9
47:8-49:9
53:22-60:1
55:4-57:5
62:10-66:1
64:4-65:5

28
crates/syntax/tests/fixtures/broken.php vendored Normal file
View file

@ -0,0 +1,28 @@
<?php
namespace Broken;
class Complete
{
public function ok(): bool
{
return true;
}
}
class Half extends
{
public function first(int $a
public function second(): void
{
if ($x {
}
}
function after_errors(): int
{
return 1;
}
class

View file

@ -0,0 +1,12 @@
# outline
namespace Broken @2:0-27:5 sel 2:10-2:16
class Complete @4:0-10:1 sel 4:6-4:14
method ok (): bool @6:4-9:5 sel 6:20-6:22
method second (): void @14:4-20:1 sel 16:20-16:26
method after_errors (): int @22:0-25:1 sel 22:9-22:21
# folding
5:0-10:1
7:4-9:5
17:4-20:1
18:15-19:5
23:0-25:1

View file

@ -0,0 +1,39 @@
<html>
<body>
<?php
if (!function_exists('greet')) {
function greet(string $name = 'world'): string
{
return "Hello, {$name}!";
}
}
$handler = function (int $code) {
function not_listed_inside_closure() {}
return $code;
};
$double = fn(int $x): int => $x * 2;
return new class ('db') extends Migration implements Countable {
public function __construct(private string $connection)
{
}
public function up(): void
{
$inner = new class {
public function hidden(): void {}
};
}
public function count(): int
{
return 0;
}
};
?>
<p><?= greet() ?></p>
</body>
</html>

View file

@ -0,0 +1,16 @@
# outline
function greet (string $name): string @5:4-8:5 sel 5:13-5:18
class class@anonymous extends Migration implements Countable @18:11-34:1 sel 18:11-18:16
method __construct (string $connection) @19:4-21:5 sel 19:20-19:31
property $connection string @19:32-19:58 sel 19:47-19:58
method up (): void @23:4-28:5 sel 23:20-23:22
method count (): int @30:4-33:5 sel 30:20-30:25
# folding
4:31-9:1
6:4-8:5
11:32-14:1
18:63-34:1
20:4-21:5
24:4-28:5
25:27-27:9
31:4-33:5

View file

@ -0,0 +1,64 @@
<?php
namespace App\Models;
use App\Contracts\HasLabel;
use App\Support\Str;
use function App\Support\slugify;
#[\Attribute(\Attribute::TARGET_CLASS)]
final class Entity
{
}
/**
* Base model for every entity.
*/
#[Entity]
abstract class Model
{
protected static int $instances = 0;
#[\Deprecated]
abstract public function key(): string|int;
public function &attributes(): array
{
static $cache = [];
return $cache;
}
}
trait Timestamps
{
public ?\DateTimeImmutable $createdAt = null;
public function touch(\DateTimeImmutable $at = new \DateTimeImmutable()): void
{
$this->createdAt = $at;
}
}
namespace App\Enums;
enum Status: string implements \App\Contracts\HasLabel
{
case Draft = 'draft';
case Published = 'published';
const DEFAULT = self::Draft;
public function label(): string
{
return match ($this) {
self::Draft => 'Draft',
self::Published => 'Published',
};
}
}
enum Suit
{
case Hearts;
case Spades;
}

View file

@ -0,0 +1,31 @@
# outline
namespace App\Models @2:0-39:1 sel 2:10-2:20
class Entity @8:0-11:1 sel 9:12-9:18
class Model @16:0-29:1 sel 17:15-17:20
property $instances int @19:4-19:40 sel 19:25-19:35
method key (): string|int @21:4-22:47 sel 22:29-22:32
method attributes (): array @24:4-28:5 sel 24:21-24:31
trait Timestamps @31:0-39:1 sel 31:6-31:16
property $createdAt ?\DateTimeImmutable @33:4-33:49 sel 33:31-33:41
method touch (\DateTimeImmutable $at): void @35:4-38:5 sel 35:20-35:25
namespace App\Enums @41:0-63:1 sel 41:10-41:19
enum Status : string implements \App\Contracts\HasLabel @43:0-57:1 sel 43:5-43:11
enumCase Draft 'draft' @45:4-45:25 sel 45:9-45:14
enumCase Published 'published' @46:4-46:33 sel 46:9-46:18
constant DEFAULT @48:4-48:32 sel 48:10-48:17
method label (): string @50:4-56:5 sel 50:20-50:25
enum Suit @59:0-63:1 sel 59:5-59:9
enumCase Hearts @61:4-61:16 sel 61:9-61:15
enumCase Spades @62:4-62:16 sel 62:9-62:15
# folding
4:0-6:33
10:0-11:1
13:0-15:3
18:0-29:1
25:4-28:5
32:0-39:1
36:4-38:5
44:0-57:1
51:4-56:5
52:29-55:9
60:0-63:1

View file

@ -0,0 +1,4 @@
<?php
/** Prüfung — 🦦 otters use tools. */
const ÄRGER = '🦦🦦'; class Café { public function naïve(string $straße): string { return $straße; } }
$otters = "🦦🦦🦦"; function grüße(string $gruß = "🦦"): void {}

View file

@ -0,0 +1,6 @@
# outline
constant ÄRGER @2:0-2:21 sel 2:6-2:11
class Café @2:22-2:102 sel 2:28-2:32
method naïve (string $straße): string @2:35-2:100 sel 2:51-2:56
function grüße (string $gruß): void @3:20-3:64 sel 3:29-3:34
# folding

112
crates/syntax/tests/perf.rs Normal file
View file

@ -0,0 +1,112 @@
//! Parse timing for a generated 1 MB PHP file (budget: under 50 ms).
//!
//! Ignored by default because timings in debug builds mean nothing. Run in
//! release on an idle machine:
//! `cargo test --release -p lutra-syntax --test perf -- --ignored --nocapture`.
#![allow(
clippy::unwrap_used,
clippy::indexing_slicing,
clippy::string_slice,
reason = "tests may panic"
)]
use std::time::{Duration, Instant};
use lutra_syntax::{Parser, folding, outline};
use lutra_text::Edit;
/// Generates a PHP file of at least `bytes` bytes made of namespaced
/// classes with properties, a promoted constructor, methods, arrays and
/// doc comments.
fn generate(bytes: usize) -> String {
let mut text = String::from(
"<?php\n\ndeclare(strict_types=1);\n\nnamespace Bench\\Generated;\n\nuse Bench\\Support\\Collection;\n\n",
);
let mut index = 0usize;
while text.len() < bytes {
text.push_str(&format!(
r#"/**
* Generated class number {index}.
*/
final class Service{index} implements \Countable
{{
public const int LIMIT = {index};
private array $items = ['a' => 1, 'b' => [2, 3], 'c' => "four {index}"];
public function __construct(private readonly Collection $collection, protected ?string $name = null)
{{
}}
public function find(int $id, string ...$tags): ?array
{{
foreach ($this->items as $key => $value) {{
if ($key === $id && \in_array($value, $tags, true)) {{
return ['id' => $id, 'value' => $value];
}}
}}
return match ($id) {{
0 => null,
default => $this->collection->map(fn (int $x): int => $x * {index})->all(),
}};
}}
public function count(): int
{{
return \count($this->items) + self::LIMIT;
}}
}}
"#
));
index += 1;
}
text
}
/// The fastest of `runs` timings of `work`.
fn best_of(runs: usize, mut work: impl FnMut()) -> Duration {
(0..runs)
.map(|_| {
let started = Instant::now();
work();
started.elapsed()
})
.min()
.unwrap()
}
#[test]
#[ignore = "timing; run in release"]
fn parse_one_megabyte() {
let text = generate(1024 * 1024);
let mut parser = Parser::new().unwrap();
let tree = parser.parse(&text);
assert!(!tree.has_errors());
let parse = best_of(5, || {
parser.parse(&text);
});
let outline_time = best_of(5, || {
outline(&tree);
});
let folding_time = best_of(5, || {
folding(&tree);
});
let middle = text.len() / 2;
let middle = (middle..text.len())
.find(|offset| text.is_char_boundary(*offset))
.unwrap();
let reparse = best_of(5, || {
parser.reparse(&tree, &[Edit::insert(middle, " ")]).unwrap();
});
println!(
"1 MB PHP ({} bytes, {} top-level items): parse {:?}, reparse after one keystroke {:?}, outline {:?}, folding {:?}",
text.len(),
outline(&tree).len(),
parse,
reparse,
outline_time,
folding_time
);
}

View file

@ -0,0 +1,8 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc c8b0a3ee622e3fac3ec69a94aebc22f23c9b3870156159ba6d9c2c5387d5eced # shrinks to fixture = Index(0), steps = [[(5318099958520493566, 19, 12), (10643632058251538265, 19, 18)], [(11062977690082286900, 37, 1)], [(3728561719478013405, 20, 10)]]
cc 3129b8640200f6a3b49b6579ba02346c578c68a5fb37bf929f93fb1aa0f4ef9b # shrinks to fixture = Index(14757395258967641293), steps = [[(14373769676898819633, 13, 21)], [(0, 0, 0)]]

View file

@ -0,0 +1,210 @@
//! Property tests: parsing untrusted text never panics, and an incremental
//! reparse gives the same tree, outline and folding as a fresh parse.
//!
//! 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.
#![allow(
clippy::unwrap_used,
clippy::indexing_slicing,
clippy::string_slice,
reason = "tests may panic"
)]
use std::path::Path;
use lutra_syntax::{Parser, SyntaxError, folding, outline};
use lutra_text::Edit;
use proptest::prelude::*;
/// PHP fragments edits insert, chosen to open and close constructs.
const FRAGMENTS: &[&str] = &[
"",
"{",
"}",
"(",
")",
";",
"\n",
" ",
"class X {",
"function f() {",
"$a = [",
"]",
"/*",
"*/",
"//",
"'",
"\"",
"<?php ",
"?>",
"namespace N;",
"public int $p;",
"enum E { case A; }",
"#[A]",
"=> ",
"ü",
"🦦",
"\r\n",
"<<<EOT\n",
"\nEOT;\n",
];
/// The fixture texts edits start from.
fn fixtures() -> Vec<String> {
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures");
let mut texts: Vec<String> = std::fs::read_dir(dir)
.unwrap()
.map(|entry| entry.unwrap().path())
.filter(|path| path.extension().is_some_and(|ext| ext == "php"))
.map(|path| std::fs::read_to_string(path).unwrap())
.collect();
texts.sort();
texts
}
/// Moves `offset` down to the nearest char boundary of `text`.
fn floor_boundary(text: &str, offset: usize) -> usize {
let mut offset = offset.min(text.len());
while !text.is_char_boundary(offset) {
offset -= 1;
}
offset
}
/// A strategy for one edit as (start seed, length seed, fragment index).
fn edit_seed() -> impl Strategy<Value = (usize, usize, usize)> {
(any::<usize>(), 0usize..40, 0..FRAGMENTS.len())
}
/// Turns seeds into a valid edit on `text`.
fn edit_for(text: &str, (start, len, fragment): (usize, usize, usize)) -> Edit {
let start = floor_boundary(text, start % (text.len() + 1));
let end = floor_boundary(text, start + len);
Edit::replace(start..end.max(start), FRAGMENTS[fragment])
}
proptest! {
#![proptest_config(ProptestConfig::with_cases(256))]
#[test]
fn random_bytes_never_panic(bytes in proptest::collection::vec(any::<u8>(), 0..2048)) {
let text = String::from_utf8_lossy(&bytes);
let mut parser = Parser::new().unwrap();
let tree = parser.parse(&text);
let _ = outline(&tree);
let _ = folding(&tree);
}
#[test]
fn random_php_tokens_never_panic(parts in proptest::collection::vec(0..FRAGMENTS.len(), 0..200)) {
let text: String = parts.into_iter().map(|index| FRAGMENTS[index]).collect();
let mut parser = Parser::new().unwrap();
let tree = parser.parse(&text);
let _ = outline(&tree);
let _ = folding(&tree);
}
#[test]
fn reparse_equals_fresh_parse(
fixture in any::<prop::sample::Index>(),
steps in proptest::collection::vec(proptest::collection::vec(edit_seed(), 1..4), 1..6),
) {
let texts = fixtures();
let mut text = fixture.get(&texts).clone();
let mut parser = Parser::new().unwrap();
let mut tree = parser.parse(&text);
for step in steps {
let mut edits: Vec<Edit> = Vec::new();
for seed in step {
let edit = edit_for(&text, seed);
if edits.iter().all(|other| other.range.end <= edit.range.start || edit.range.end <= other.range.start) {
edits.push(edit);
}
}
tree = parser.reparse(&tree, &edits).unwrap();
let mut buffer = lutra_text::Buffer::new(&text);
buffer.apply(&edits).unwrap();
text = buffer.text();
let fresh = parser.parse(&text);
prop_assert_eq!(tree.text().text(), text.clone());
let _ = outline(&tree);
let _ = folding(&tree);
if !fresh.has_errors() {
prop_assert_eq!(tree.to_sexp(), fresh.to_sexp());
prop_assert_eq!(outline(&tree), outline(&fresh));
prop_assert_eq!(folding(&tree), folding(&fresh));
}
}
}
#[test]
fn undo_round_trip_restores_the_tree(
fixture in any::<prop::sample::Index>(),
seeds in proptest::collection::vec(edit_seed(), 1..12),
) {
let texts = fixtures();
let original = fixture.get(&texts).clone();
let mut parser = Parser::new().unwrap();
let expected = parser.parse(&original);
let mut tree = expected.clone();
let mut text = original.clone();
let mut undo = Vec::new();
for seed in seeds {
let edit = edit_for(&text, seed);
let removed = text[edit.range.clone()].to_owned();
let start = edit.range.start;
undo.push(Edit::replace(start..start + edit.text.len(), removed));
tree = parser.reparse(&tree, std::slice::from_ref(&edit)).unwrap();
text.replace_range(edit.range.clone(), &edit.text);
}
for edit in undo.into_iter().rev() {
tree = parser.reparse(&tree, std::slice::from_ref(&edit)).unwrap();
}
prop_assert_eq!(tree.text().text(), original);
if !expected.has_errors() {
prop_assert_eq!(tree.to_sexp(), expected.to_sexp());
prop_assert_eq!(outline(&tree), outline(&expected));
prop_assert_eq!(folding(&tree), folding(&expected));
}
}
#[test]
fn invalid_edits_are_errors(start in 0usize..200, end in 0usize..200) {
let text = "<?php class Café { function ü() {} }";
let mut parser = Parser::new().unwrap();
let tree = parser.parse(text);
let valid = start <= end
&& end <= text.len()
&& text.is_char_boundary(start)
&& text.is_char_boundary(end);
match parser.reparse(&tree, &[Edit::delete(start..end)]) {
Ok(_) => prop_assert!(valid),
Err(SyntaxError::Edit(_)) => prop_assert!(!valid),
Err(other) => prop_assert!(false, "unexpected error {other}"),
}
}
}
/// Deeply nested brackets must not exhaust the stack in the outline or
/// folding walk.
#[test]
fn deep_nesting_does_not_overflow() {
let depth = 100_000;
let text = format!("<?php $a = {}{};", "[".repeat(depth), "]".repeat(depth));
let mut parser = Parser::new().unwrap();
let tree = parser.parse(&text);
let _ = outline(&tree);
assert!(folding(&tree).is_empty());
let nested = format!(
"<?php {} class Deep {{}} {}",
"if (1) {".repeat(5_000),
"}".repeat(5_000)
);
let tree = parser.parse(&nested);
let _ = outline(&tree);
let _ = folding(&tree);
}

View file

@ -0,0 +1,96 @@
//! Outline and folding snapshots for the PHP fixtures in `tests/fixtures`.
//!
//! Each `NAME.php` has a `NAME.snap` next to it holding the rendered
//! outline and folding ranges. Run with `LUTRA_BLESS=1` to rewrite the
//! snapshots after an intended change, then review the diff.
#![allow(
clippy::unwrap_used,
clippy::indexing_slicing,
clippy::string_slice,
reason = "tests may panic"
)]
use std::fmt::Write as _;
use std::path::Path;
use lutra_syntax::{OutlineItem, Parser, Range, folding, outline};
/// Renders a range as `line:column-line:column`.
fn range(range: &Range) -> String {
format!(
"{}:{}-{}:{}",
range.start.line, range.start.column, range.end.line, range.end.column
)
}
/// Renders outline items one per line, children indented.
fn render_items(items: &[OutlineItem], depth: usize, out: &mut String) {
for item in items {
let detail = item
.detail
.as_deref()
.map(|detail| format!(" {detail}"))
.unwrap_or_default();
writeln!(
out,
"{}{} {}{} @{} sel {}",
" ".repeat(depth),
item.kind.as_str(),
item.name,
detail,
range(&item.range),
range(&item.selection_range)
)
.unwrap();
render_items(&item.children, depth + 1, out);
}
}
/// Parses `name.php` and compares the rendering with `name.snap`.
fn check(name: &str) {
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures");
let source = std::fs::read_to_string(dir.join(format!("{name}.php"))).unwrap();
let mut parser = Parser::new().unwrap();
let tree = parser.parse(&source);
let mut rendered = String::from("# outline\n");
render_items(&outline(&tree), 0, &mut rendered);
rendered.push_str("# folding\n");
for fold in folding(&tree) {
writeln!(rendered, "{}", range(&fold)).unwrap();
}
let snapshot = dir.join(format!("{name}.snap"));
if std::env::var_os("LUTRA_BLESS").is_some() {
std::fs::write(&snapshot, &rendered).unwrap();
return;
}
let expected = std::fs::read_to_string(&snapshot)
.unwrap_or_default()
.replace("\r\n", "\n");
assert_eq!(rendered, expected, "snapshot {name}.snap differs");
}
#[test]
fn braced_namespaces() {
check("braced_namespaces");
}
#[test]
fn unbraced_namespace() {
check("unbraced_namespace");
}
#[test]
fn scripts_and_anonymous() {
check("scripts_and_anonymous");
}
#[test]
fn broken() {
check("broken");
}
#[test]
fn unicode_positions() {
check("unicode_positions");
}

View file

@ -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
@ -194,6 +194,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 |
@ -211,6 +223,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.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 |
| 2026-10-16 | minor | M1.8: UI commands (`ui.registerCommands`, `uiCommand`, `ui` in listCommands), global keymap, command palette |

View file

@ -1,6 +1,6 @@
# Gaps
> **Status:** M0 closed G1; G2 under way (text buffer, engine buffers, tabs and editor in the app, recovery journal); G3 M1 part done (project tree, palette, settings dialog, themes); G14 English UI catalog in place · **Last updated:** 2026-10-16
> **Status:** M0 closed G1; G2 under way (text buffer, engine buffers, tabs and editor in the app, recovery journal); G3 M1 part done (project tree, palette, settings dialog, themes); G4 under way (tree-sitter outline and folding library); G14 English UI catalog in place · **Last updated:** 2026-10-16
Every known shortfall, ranked. This is the work list: unless the owner gives a task, take the highest open gap. Hours are agent wall-clock hours for one agent, all estimated.
@ -25,6 +25,8 @@ Every known shortfall, ranked. This is the work list: unless the owner gives a t
G2 progress: the engine text buffer landed (M1.1, `crates/text`: rope, UTF-16 and char positions, atomic edit batches, line ending policy). M1.3 added engine buffers with versions, the edit protocol, save and save all, and reloading on external changes. M1.6 added tabs and a CodeMirror 6 editor synced to engine buffers (version-based edits with resync, CRLF-aware offsets), save and save all by engine shortcuts, the Save / Don't Save / Cancel question and a notice for files changed on disk. M1.7 added the crash-recovery journal (debounced atomic entries per dirty buffer, `recovery.*` commands, restore dialog; not yet checked in the running app). M1.13 made re-opening an open file switch to its tab and keeps the folders of open files watched. Still open: tab management beyond open/close, a conflict UI (compare and merge with the disk version), autosave, editor settings (font size, soft wrap); estimate lowered to ~16 h.
G4 progress: M2.1 added the structural half in `crates/syntax`: tree-sitter PHP parse and incremental reparse, outline (namespaces, class-likes, functions, members, promoted properties, enum cases; anonymous classes marked) and folding ranges, an 8 MiB parse cap, proptests and snapshots. Not visible yet: highlighting (M2.2) and the Structure window (M2.7) are open. Finding: a full parse of 1 MB takes 364–553 ms on the dev machine (target 50 ms; reparse 7–11 ms), so parsing must stay off the engine lock and the index must parse in parallel.
G11 progress: M1.7 added the crash-recovery journal: unsaved buffers are written atomically about 1 s after the last edit and offered back after a crash; corrupt entries are skipped with a warning. Covered by a property test (random edits, crash, restore equals the buffer) and a headless control-channel test; not yet checked by killing the running app (gaming mode). Open: journal writes run under the engine lock (8.5 ms for 1 MiB, release), two instances on one project share a journal, local history.
G14 progress: M1.11 moved every UI string in `ui/src` into the English catalog `ui/src/i18n/en.json` behind `t(key, params?)`, enforced by `vue/no-bare-strings-in-template` and a catalog test. Messages the engine sends (`EngineError.message`, the slogan from `app.about`) are still English text; they need message keys with params before a second language can cover them.
@ -39,6 +41,7 @@ Known smaller items from M0:
| Date | Change | Summary |
|---|---|---|
| 2026-10-16 | minor | G4 note: tree-sitter syntax library, outline and folding (M2.1) |
| 2026-10-16 | minor | G3: settings dialog, theme picker (M1.9b) |
| 2026-10-16 | minor | G3: command palette, global keymap, UI commands (M1.8) |
| 2026-10-16 | minor | G2/G3: re-open focuses the tab, open buffers' folders watched, truncated listings shown (M1.13) |

View file

@ -12,9 +12,9 @@ Hours are the estimated agent wall-clock hours for one agent to reach behaviour
| Area | Weight | Score | Missing | Hours (one agent) | Evidence |
|---|---:|---:|---|---:|---|
| Editor core | 12 | 9% (est.) | syntax highlighting (M2), code folding, soft wrap and other editor settings, preview tab, pinned/split/reordered tabs, close others/all, reopen closed tab, tab limit, conflict UI for files changed on disk, autosave, local history, encodings other than UTF-8, large-file mode, column selection and multi-caret checked against the docs; recovery journal not yet checked in the running app (gaming mode) | ~106 (est.) | M1.13: opening a file that is already open switches to its tab (`bufferFocused`; engine test, Vitest, control-channel test; live check pending (gaming mode)); files in folders the tree never expanded still reload or report changes on disk, because the parent directory of every open buffer stays watched (engine tests). M1.7: crash-recovery journal (`crates/engine/src/journal.rs`, `cmd/recovery.rs`): dirty buffers are written atomically to `<data_dir>/recovery/<project-id>/` about 1 s after the last edit (at least every 2 s while typing), never per keystroke; removed on save, close and discard; `recoveryAvailable` after `project.open`, `recovery.list/restore/discard`; restored buffers are dirty and keep line ending and BOM; corrupt entries are moved aside with a warning. Restore dialog (`ui/src/components/recovery/`: Restore all / selected / Discard, time, changed-on-disk hint). Tests: engine dropped mid-edit and a new engine restores the exact CRLF + BOM text, corrupt entries, removal paths, a property test of random edit sequences → crash → restore equals the buffer (`crates/engine/tests/recovery.rs`, 10 tests), the same flow headless over the control channel (`crates/control/tests/recovery.rs`), 10 Vitest tests for the dialog. 1 MiB entry write: 8.5 ms median (release, measured). Graded against `plan/phpstorm/04-recovery.md`. M1.6: tabs and a CodeMirror 6 editor in the app (`ui/src/components/editor/`, `ui/src/stores/editor.ts`): open from the project tree or engine events, activate, close by button, middle click or `Mod+W`, dirty dot, Save / Don't Save / Cancel on closing a dirty tab, `Mod+S` / `Mod+Alt+S` from engine command specs, non-blocking notice for a dirty file changed or deleted on disk; local edits go to `buffer.edit` with version-based resync, CRLF files keep `\r\n`; undo/redo, multiple selections, search and bracket matching from CodeMirror's basic setup. Vitest: a burst of 400 keystrokes with stale versions and remote edits loses none, a CRLF burst with deletions converges, store and component tests against a fake engine (`ui/tests/editor/`, 22 tests). Checked in the app on Windows 11 with `--control` and `ui.screenshot`: typing via the UI and via `buffer.edit`, save to disk, close question, middle click, disk-change notice. 1 MB file (16,385 lines): engine `file.open` 80 ms over the control channel (debug build, measured), editor state 1–6 ms and first rendered view 4–11 ms in Chromium (measured), ≈ 90 ms in total (estimated, budget 150 ms). Graded against `plan/phpstorm/03-editor-tabs.md`. `crates/text`: rope buffer, positions, edits (M1.1, unit tests + proptests). M1.3: engine buffers with versions and dirty state, `file.open`, `buffer.get`, `buffer.edit` (UTF-16 change sets, `stale_version`), `file.save`, `file.saveAll`, `buffer.close` with unsaved-changes guard, line ending and BOM kept on save, clean buffers reload on external change; 14 integration tests on temp dirs (`crates/engine/tests/workspace.rs`) |
| Editor core | 12 | 9% (est.) | syntax highlighting (M2), code folding, soft wrap and other editor settings, preview tab, pinned/split/reordered tabs, close others/all, reopen closed tab, tab limit, conflict UI for files changed on disk, autosave, local history, encodings other than UTF-8, large-file mode, column selection and multi-caret checked against the docs; recovery journal not yet checked in the running app (gaming mode) | ~106 (est.) | M2.1: `crates/syntax` parses PHP with tree-sitter (incremental reparse from `lutra_text` edits) and computes folding ranges (brace blocks, arrays, comments, heredocs, `use` runs); library only, nothing visible in the editor yet, so the score is unchanged. Tests: outline/folding snapshots for five PHP 8.3 fixtures, proptests (random bytes and token soups never panic, reparse equals a fresh parse, undo round trip). 1 MB parse 364–553 ms, reparse after one keystroke 7–11 ms (release, measured, machine busy). M1.13: opening a file that is already open switches to its tab (`bufferFocused`; engine test, Vitest, control-channel test; live check pending (gaming mode)); files in folders the tree never expanded still reload or report changes on disk, because the parent directory of every open buffer stays watched (engine tests). M1.7: crash-recovery journal (`crates/engine/src/journal.rs`, `cmd/recovery.rs`): dirty buffers are written atomically to `<data_dir>/recovery/<project-id>/` about 1 s after the last edit (at least every 2 s while typing), never per keystroke; removed on save, close and discard; `recoveryAvailable` after `project.open`, `recovery.list/restore/discard`; restored buffers are dirty and keep line ending and BOM; corrupt entries are moved aside with a warning. Restore dialog (`ui/src/components/recovery/`: Restore all / selected / Discard, time, changed-on-disk hint). Tests: engine dropped mid-edit and a new engine restores the exact CRLF + BOM text, corrupt entries, removal paths, a property test of random edit sequences → crash → restore equals the buffer (`crates/engine/tests/recovery.rs`, 10 tests), the same flow headless over the control channel (`crates/control/tests/recovery.rs`), 10 Vitest tests for the dialog. 1 MiB entry write: 8.5 ms median (release, measured). Graded against `plan/phpstorm/04-recovery.md`. M1.6: tabs and a CodeMirror 6 editor in the app (`ui/src/components/editor/`, `ui/src/stores/editor.ts`): open from the project tree or engine events, activate, close by button, middle click or `Mod+W`, dirty dot, Save / Don't Save / Cancel on closing a dirty tab, `Mod+S` / `Mod+Alt+S` from engine command specs, non-blocking notice for a dirty file changed or deleted on disk; local edits go to `buffer.edit` with version-based resync, CRLF files keep `\r\n`; undo/redo, multiple selections, search and bracket matching from CodeMirror's basic setup. Vitest: a burst of 400 keystrokes with stale versions and remote edits loses none, a CRLF burst with deletions converges, store and component tests against a fake engine (`ui/tests/editor/`, 22 tests). Checked in the app on Windows 11 with `--control` and `ui.screenshot`: typing via the UI and via `buffer.edit`, save to disk, close question, middle click, disk-change notice. 1 MB file (16,385 lines): engine `file.open` 80 ms over the control channel (debug build, measured), editor state 1–6 ms and first rendered view 4–11 ms in Chromium (measured), ≈ 90 ms in total (estimated, budget 150 ms). Graded against `plan/phpstorm/03-editor-tabs.md`. `crates/text`: rope buffer, positions, edits (M1.1, unit tests + proptests). M1.3: engine buffers with versions and dirty state, `file.open`, `buffer.get`, `buffer.edit` (UTF-16 change sets, `stale_version`), `file.save`, `file.saveAll`, `buffer.close` with unsaved-changes guard, line ending and BOM kept on save, clean buffers reload on external change; 14 integration tests on temp dirs (`crates/engine/tests/workspace.rs`) |
| Project view, VFS | 6 | 8% (est.) | views list (project / scopes), toolbar (Select Opened File, Expand/Collapse All), sort and display options, show/hide excluded, distinct icons for library and excluded folders, file colours, speed search, preview, file operations | ~37 (est.) | `lutra-vfs` (M1.2): lazy sorted listing, ignore rules (.gitignore, .ignore, info/exclude, global excludes, Lutra defaults), native file watching via `notify` with a polling fallback, capped UTF-8 reads, atomic writes; 34 tests on temp dirs, watcher tests run on both backends (`crates/vfs/tests`). M1.5: project tree UI (lazy listing, keyboard navigation, dimmed ignored entries, event refresh) in `ui/src/components/project/`, Vitest against a mocked engine. M1.3: `project.open`, `project.close`, `project.children` (watches listed directories, capped at 256 native / 32 polling, least recently listed dropped), `treeChanged` events from disk, `events.subscribe` on the control channel with a TCP test (`crates/control/tests/events.rs`). M1.4: the tree runs against the engine in the app: folder picker (`project.openDialog`) and `lutra-desktop --control PORT PATH` open a project, the tree lists it lazily with ignored (`var/` from `.gitignore`) and excluded (`node_modules`) entries dimmed, a file created on disk appears in an expanded folder within ~100 ms; verified with `ui.screenshot` on Windows 11 and Vitest (`ui/tests/project/`, `ui/tests/ipcEvents.test.ts`). M1.13: a directory listed only partly (more than 100,000 entries) ends with a "Listing truncated" note row (Vitest). M1.12: a folder that cannot be opened from the picker or the command line (including `unsaved_changes` when switching projects) and stopped file watching show as toasts instead of stderr (`apps/lutra-desktop/src/host.rs`, `ui/src/stores/notifications.ts`, `ui/tests/notifications/`, 19 Vitest tests; live check pending, gaming mode); score unchanged. Graded against `plan/phpstorm/02-project-view.md`: tool window, folder-first tree, dimmed ignored/excluded, keyboard navigation and live refresh exist; most toolbar, view and display options do not |
| Navigation | 10 | 0% | everything (M1.8: a command palette over commands only, no go-to-file/class/symbol yet; score unchanged) | ~120 (est.) | M1.8: `ui/src/components/palette/`, `ui/src/commands/` (fuzzy ranking, recent commands, global keymap), Vitest `ui/tests/palette/`, `ui/tests/commands/` |
| Navigation | 10 | 0% | everything (M1.8: a command palette over commands only, no go-to-file/class/symbol yet; score unchanged) | ~120 (est.) | M2.1: file outline in `crates/syntax` (namespaces braced and unbraced, classes, interfaces, traits, enums with cases, functions, methods, properties incl. promoted ones, constants; UTF-16 ranges and short signatures), the base for the Structure window (M2.7) and the symbol index (M2.5); not reachable from the UI yet, score unchanged. M1.8: `ui/src/components/palette/`, `ui/src/commands/` (fuzzy ranking, recent commands, global keymap), Vitest `ui/tests/palette/`, `ui/tests/commands/` |
| Search and replace | 6 | 0% | everything | ~80 (est.) | — |
| Code completion | 10 | 0% | everything | ~250 (est.) | — |
| Inspections and quick-fixes | 8 | 0% | everything | ~300 (est.) | — |
@ -63,6 +63,7 @@ The project tree is the first user-visible feature (Project view 8%, estimated);
| Date | Change | Summary |
|---|---|---|
| 2026-10-16 | minor | M2.1: Editor core and Navigation evidence (tree-sitter parse, outline, folding library), scores unchanged |
| 2026-10-16 | minor | M1.9b: Settings row 4% → 7% (est.), settings dialog; M1 done |
| 2026-10-16 | minor | M1.8: Navigation and Settings/keymaps evidence (palette, global keymap), scores unchanged |
| 2026-10-16 | minor | M1.12: Project view evidence (picker errors as toasts), scores unchanged |