pub trait AsyncCompletionSource:
Send
+ Sync
+ Debug {
// Required method
fn produce_async(
&self,
ctx: InsertContextSnapshot,
sink: Arc<dyn CandidateSink>,
token: CancellationToken,
) -> Pin<Box<dyn Future<Output = ()> + Send>>;
}Expand description
Asynchronous completion source. Used for sources that must
round-trip (LSP), watch a long-running task, or otherwise
can’t deliver candidates synchronously. The aggregator calls
Self::produce_async at popup-open and on every
isIncomplete re-fire; the returned future pushes
candidates into a host-supplied CandidateSink as they
arrive.
The trait deliberately hands the host a generic Future –
lattice-completion does not depend on tokio. The host
(lattice-ui-tui today, the plugin runtime later) drives
the future on its own executor and is free to cancel via
the supplied [CancellationToken].
Required Methods§
Sourcefn produce_async(
&self,
ctx: InsertContextSnapshot,
sink: Arc<dyn CandidateSink>,
token: CancellationToken,
) -> Pin<Box<dyn Future<Output = ()> + Send>>
fn produce_async( &self, ctx: InsertContextSnapshot, sink: Arc<dyn CandidateSink>, token: CancellationToken, ) -> Pin<Box<dyn Future<Output = ()> + Send>>
Build the producer future. The future:
- reads the snapshot (which carries the cursor / query / trigger; the source’s own struct captures anything else it needs – handles, URIs, server lookups);
- pushes each
RawCandidateintosinkas it arrives; - checks
token.is_cancelled()at await points and bails without further pushes when set; - resolves when the source has no more candidates to produce (the aggregator marks the source “done” and stops awaiting further work for this popup instance).
Arc<dyn CandidateSink> is used (rather than borrowed
&dyn CandidateSink) so the future can outlive the
caller’s stack frame – it crosses the spawn boundary.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".