Skip to main content

lattice_plugin_host/
context_host.rs

1//! The context-provider guest world (TC.2).
2//!
3//! A WASM context provider implements the `context-plugin` world: it exports the
4//! `context` producer (`context-scopes`), and imports `tree-sitter` (so the
5//! host-owned `tree-snapshot` resource is in scope for the `borrow<>` parameter)
6//! plus the `host-services` walk seam. This module holds the **seventh
7//! `bindgen!`** (after `plugin`, `picker-source-plugin`,
8//! `completion-source-plugin`, `grammar-plugin`, `events-plugin`,
9//! `decorations-plugin`) for that world, with the same shared-types trick:
10//! `with:` points `types` / `host-services` / `tree-sitter` at the already-
11//! generated modules so a crossed `context-scope` is the SAME Rust type
12//! `WitBoundary` round-trips (`boundary_context.rs`).
13//!
14//! **Producer, async** — the `decorations` fork, and here the reason is sharper
15//! than "don't block": the guest runs a whole-buffer tree-sitter query inside
16//! `context-scopes`, so a synchronous seam would put that on the caller's
17//! thread. `exports: { default: async }`.
18//!
19//! **The `tree-sitter` `with:` points at the GRAMMAR world's module.** That is
20//! where `HostTreeSnapshot` / `HostNode` are implemented (`lib.rs`), and those
21//! resources are already added to the async linker — so an async world can take
22//! a `borrow<tree-snapshot>` without a second host impl. Pointing this world at
23//! its own freshly generated `tree-sitter` module instead would mint a second,
24//! incompatible set of resource types for the same host objects.
25
26pub(crate) mod bindings {
27    wasmtime::component::bindgen!({
28        world: "context-plugin",
29        path: "../lattice-wit/wit",
30        // A produce call suspends the guest stack; the whole-buffer query it
31        // runs must never pin the caller's thread (nor the render path).
32        exports: { default: async },
33        with: {
34            "lattice:plugin-host/types": crate::lattice::plugin_host::types,
35            "lattice:plugin-host/host-services": crate::lattice::plugin_host::host_services,
36            "lattice:plugin-host/logging": crate::lattice::plugin_host::logging,
37            // The tree resources + their `Host*` impls live with the grammar
38            // world (TS.1); reuse them rather than minting a parallel set.
39            "lattice:plugin-host/tree-sitter":
40                crate::grammar_host::bindings::lattice::plugin_host::tree_sitter,
41        },
42    });
43}