Skip to main content

Module completion

Module completion 

Source
Expand description

Structural autocomplete analysis (E005 Wave 3, US2).

Given a parsed CstDocument and a cursor byte offset, this module derives a CompletionContext describing where the cursor sits inside the RON structure (the PositionKind), what identifier fragment the user is in the middle of typing (the prefix), and a deterministic, ranked list of low-confidence CompletionItem suggestions drawn only from what is already attested in the document.

§Progressive Intelligence — structural only (project-instructions §III)

Completion here is structural: it uses the CST syntax plus identifiers that already appear in the document (sibling field names, enum-variant names, map keys), plus the always-legal Some / None and the context-legal delimiters. It carries no type information — type-aware completion is E006. Missing or ambiguous context degrades gracefully to zero suggestions, never an error (FR-014). Unknown context is not a failure; it is simply “nothing to suggest”.

§Never corrupt (project-instructions §I)

Analysis is strictly read-only over the CST. Every produced CompletionItem carries an insert_text that is syntactically valid in its position, so an accepted suggestion (spliced + re-parsed by the surface layer) round-trips through the CST. Nothing here mutates the document and nothing auto-accepts: ranks are deliberately assigned below the user’s literal input so a suggestion is never preselected (FR-012).

§WASM-clean (project-instructions §II, INV-9)

This module adds no filesystem / UI / async / native dependency — it uses only std and ronin-core’s own CST types, so the wasm32 build of ronin-core stays green.

§Deferred seams

Completion here is structural; the deeper intelligence is deferred to later epics and attaches around this read-only analysis:

  • type-aware completion — ranking + filtering candidates by an expected type (and offering type-legal field/variant names rather than merely attested ones) → E006 (schema-optional type model). The CompletionKind ordering and the CompletionContext pools are the seam a type layer refines.
  • semantic / CST-backed undo-redo of an accepted suggestion → E007 (the surface layer’s verified splice is what an undo stack records against).
  • tree / table structured editing completions → E008.
  • Bevy-registry-aware completion (real component / field names from a loaded registry, not just in-file attestation) → E009.
  • RON⇄JSON / derive-driven suggestions → E010 (interop is outside this pure-CST engine).

Structs§

CompletionContext
The full completion analysis for a cursor offset (FR-010/FR-011).
CompletionItem
A single low-confidence completion suggestion (FR-011/FR-012).

Enums§

CompletionKind
The classification of a single CompletionItem (FR-011/FR-012).
PositionKind
Where the cursor sits inside the RON structure (FR-010).

Functions§

completion_context
Analyze the cursor offset against doc and produce a CompletionContext (FR-010/FR-011/FR-012/FR-014).
completions
Convenience: the ranked, prefix-filtered suggestions for ctx (FR-012).