Skip to main content

Module boundary_grammar

Module boundary_grammar 

Source
Expand description

The grammar-extension boundary conversions (plugin-host.md §4.1, PH7.7a).

Mirrors the data a plugin authors against when it EXTENDS the vim grammar via register_{motion,operator,text_object,ex_command,action}. The grammar handling (dispatcher, parser, composition) stays native + sync + untouched (PH7.7 fork, locked): a plugin only contributes entries; it never observes or reimplements dispatch.

Two directions, matching the picker seam (boundary_picker.rs):

  • Contexts are host→guest one-way projections of the dispatch environment (project_* free fns — the contexts carry &Buffer / &CancellationToken / Option<&dyn ScopeResolver> borrows, so they cannot round-trip; the guest never sends a context back). Bulk buffer text never rides a context — it crosses via the buffer document resource handle (§4.2), so a projection reads only the owned scalars.
  • Results come back guest→host: MotionResult here; a text object returns range (NativeRange::from_wit), an operator/ex-command returns effect (NativeEffect::from_wit), parse_args returns args (NativeArgs::from_wit) — all reusing the PH7.3b conversions.

The contribution spec records (motion-spec/…) mirror each native *Spec with the apply / parse_args closure dropped — the behavior is a sync guest export the host calls back by callback-id (PH7.7b/c), not a field that crosses. Their scalar fields reuse the conversions this module adds (LatencyClass, SurfaceForm) plus the existing ArgSpec mirror; the WIT-record → native-*Spec direction is PH7.7c’s trampoline job (it needs the callback closure), so no spec from_wit lands here.

Functions§

project_action_context
Project an ActionContext (host→guest). The buffer field is NOT projected here — it rides the borrow<document> handle the trampoline mints (AP.0.1), keeping bulk rope text off the boundary; only the cursor scalar crosses in the record.
project_ex_command_context
Project an ExCommandContext (host→guest). The native range: Option<grammar::Range> is absent — the recursive grammar Range cannot cross a WIT record (the Global / NarrowTrigger precedent), so a v1 ex-command plugin gets bang / args / register / count.
project_motion_context
Project a live MotionContext into its owned WIT mirror (host→guest). Reads only the owned scalars — &Buffer, &CancellationToken, and the tree-sitter scope_resolver are host-owned and reached (if at all) through the document handle, never this record.
project_operator_context
Project an OperatorContext (host→guest). The &mut Document is not projected — mutation is the returned effect (§4.5).
project_text_object_context
Project a TextObjectContext (host→guest). The scope/comment env rides the document handle, not this record.