Skip to main content

lattice_plugin_host/
completion_host.rs

1//! The completion-source guest world (PH7.6).
2//!
3//! A WASM completion source implements the `completion-source-plugin` world: it
4//! exports `spec`/`generate` and imports the `host-services` `walk` seam
5//! (PH7.4b). This module holds the **third `bindgen!`** (after `plugin` and
6//! `picker-source-plugin`) for that world — the two-bindgen-with-shared-types
7//! trick (the `with:` map points `types` + `host-services` at the `plugin`
8//! world's generated modules so the crossed values are the SAME Rust types the
9//! boundary round-trips, PH7.3d precedent).
10//!
11//! Generator-only by design (option A): a completion source produces candidates
12//! asynchronously off the keystroke path, and the host runs the NATIVE
13//! `match_and_rank` over them (matching/ranking/annotation stay native — the
14//! sync-pipeline + paramount-#1 reason, see `wit/completion-source.wit`). The
15//! per-plugin actor task that drives the async `generate` export is the
16//! `completion_task` bridge; the adapter is `WasmCompletionSource`.
17
18pub(crate) mod bindings {
19    wasmtime::component::bindgen!({
20        world: "completion-source-plugin",
21        path: "../lattice-wit/wit",
22        // The guest `generate` export is async — a produce call suspends the
23        // guest stack, never pins the caller's thread (nor the keystroke path).
24        exports: { default: async },
25        with: {
26            // Reuse the `plugin` world's generated mirrors so a value crossing
27            // here is the same Rust type `WitBoundary` round-trips.
28            "lattice:plugin-host/types": crate::lattice::plugin_host::types,
29            "lattice:plugin-host/host-services": crate::lattice::plugin_host::host_services,
30            "lattice:plugin-host/logging": crate::lattice::plugin_host::logging,
31        },
32    });
33}