Skip to main content

Module grammar_host

Module grammar_host 

Source
Expand description

The grammar-extension guest world (PH7.7b).

A grammar plugin implements the grammar-plugin world: it imports the grammar register API (host-provided) and exports register-grammar (the host calls it once to drive registration) + the grammar-callbacks behaviors (apply-* / parse-ex-args, dispatched by callback-id). This module holds the fourth bindgen! (after plugin, picker-source-plugin, completion-source-plugin) for that world — the two-bindgen-with-shared-types trick (with: points types at the plugin world’s generated module so a crossed value is the SAME Rust type WitBoundary round-trips, the PH7.3d precedent).

Fully synchronous (the PH7.7 fork). Unlike picker/completion, a grammar apply resolves on the keystroke path — a motion must return inline to compose with its operator (async would break operator∘motion atomicity + dot-repeat/macros). So the bindgen! sets no exports: { default: async }: the register-grammar + grammar-callbacks exports are sync-callable from the dispatch thread, bounded by fuel + epoch (a Reflex-class budget, PH7.7c). No actor task — the sync trampoline calls the guest directly (PH7.7c).

Registration flow: the host calls the guest’s register-grammar export; the guest calls the imported register-* host functions; those record into the Store’s GrammarContributions (via the grammar::Host impl on PluginState, lib.rs); after the export returns, the host drains the contributions and builds native *Specs with trampoline applys (PH7.7c).

Structs§

GrammarContributions
The per-plugin accumulator the grammar::Host impl records into during register-grammar (lib.rs). Held in PluginState; drained by the host after the registration export returns (PH7.7c). The record_* methods are the sync host-func bodies (they only push — they cannot trap), factored here (the host_services::walk_within_grant precedent) so the recording logic is unit-testable without a PluginState / guest.

Enums§

RecordedContribution
One grammar contribution a plugin declared through the register-* API, recorded verbatim (name + doc + WIT spec metadata + the guest’s callback id). The host drains these after register-grammar returns and builds a native *Spec with a trampoline apply/parse_args stamped SourceLayer::Plugin (PH7.7c). The WIT spec is held as-is — its scalar fields convert at drain time via boundary_grammar (LatencyClass/SurfaceForm) + the existing ArgSpec mirror; the native *Spec cannot be built until the trampoline closure exists.