vernac / architecture, expressed.
Browse documentation

Declaration recovery for editor snapshots

Status: implemented in 0.5.0 development. This is editor infrastructure, not a relaxation of Vernac syntax or a replacement for Java compilation.

Purpose

Keep complete, independently recognizable declarations available when the user temporarily breaks another declaration in the same file. This is a prerequisite for live Java API completion before generation. It does not implement that API projection itself, automatic generation, compilation or Hot Swap.

Shared editor pipeline

EditorSourceParser uses the existing ANTLR grammar and AST builder. It collects syntax errors and records the enclosing top-level declaration. It excludes any declaration that owns a syntax error, contains a recovered error node or rule exception, or fails the existing name validation. It builds the file model from accepted declarations only. It also retains accepted parse contexts for tooling.

VernacProjectLoader.loadForAnalysis indexes those partial file models, including unsaved snapshots. Java projection and native type/navigation tooling use the same accepted contexts. Local declarations are matched by source line/column rather than by their position in the original declaration list. External module views retain their existing contract-order mapping because their rendered source positions can differ from producer metadata.

Source offsets remain based on the actual document, including Unicode and UTF-16 conversion at the editor boundary. No text is deleted or padded for recovery. Terms survive independently when their declarations are complete.

Guarantees and limits

Strict builds

VernacSourceParser.parse, VernacProjectLoader.load, and compiler/build entrypoints retain the strict parser. They do not compile the editor’s recovered subset. A syntax error prevents successful generation exactly as before; this change neither writes generated output nor changes schema/migration history.

Regression coverage

Tests cover unclosed behavior blocks, malformed parameters, forbidden names, incomplete Java expressions in balanced blocks, semantic errors, sibling-file errors, unsaved renames, invalid headers, Unicode source ranges, retained Java injection/navigation, external module views and strict build rejection. A deterministic set of small deletions around declarations and bodies also checks that ordinary typing states do not crash recovery.