SourceSupport

Trait SourceSupport 

Source
pub trait SourceSupport:
    Send
    + Sync
    + 'static {
    // Required methods
    fn source_id(&self) -> &'static str;
    fn complete<'a>(
        &'a self,
        ctx: &'a CompletionContext,
        content: &'a str,
    ) -> Pin<Box<dyn Future<Output = Vec<CompletionItem>> + Send + 'a>>;

    // Provided methods
    fn priority(&self) -> u32 { ... }
    fn is_available(&self, _ctx: &CompletionContext) -> bool { ... }
    fn resolve<'a>(
        &'a self,
        item: &'a CompletionItem,
    ) -> Pin<Box<dyn Future<Output = CompletionItem> + Send + 'a>> { ... }
    fn execute(&self, _item: &CompletionItem) { ... }
    fn trigger_characters(&self) -> Option<&[char]> { ... }
}
Expand description

Trait for completion source implementations

External plugins implement this trait to provide completions. Similar to treesitter’s LanguageSupport trait.

§Example

struct LspCompletionSource { client: LspClient }

impl SourceSupport for LspCompletionSource {
    fn source_id(&self) -> &'static str { "lsp" }
    fn priority(&self) -> u32 { 50 }  // Higher priority than buffer

    fn complete(&self, ctx: &CompletionContext, content: &str)
        -> Pin<Box<dyn Future<Output = Vec<CompletionItem>> + Send + '_>>
    {
        Box::pin(async move {
            self.client.request_completion(ctx).await
        })
    }
}

Required Methods§

Source

fn source_id(&self) -> &'static str

Unique identifier for this source (e.g., “buffer”, “lsp”, “path”)

Source

fn complete<'a>( &'a self, ctx: &'a CompletionContext, content: &'a str, ) -> Pin<Box<dyn Future<Output = Vec<CompletionItem>> + Send + 'a>>

Fetch completions asynchronously

Called by the saturator in a background task.

Provided Methods§

Source

fn priority(&self) -> u32

Priority for sorting results (lower = higher priority)

Default is 100. LSP sources typically use 50, buffer sources use 100.

Source

fn is_available(&self, _ctx: &CompletionContext) -> bool

Check if this source is available for the given context

Called before complete() to filter out unavailable sources.

Source

fn resolve<'a>( &'a self, item: &'a CompletionItem, ) -> Pin<Box<dyn Future<Output = CompletionItem> + Send + 'a>>

Optional: Resolve additional details for a completion item

Called when an item is selected to fetch documentation, etc.

Source

fn execute(&self, _item: &CompletionItem)

Optional: Execute post-selection action

Called after a completion is confirmed (e.g., to add imports).

Source

fn trigger_characters(&self) -> Option<&[char]>

Optional: Characters that trigger completion immediately

For example, LSP might return [‘.’, ‘:’, ‘<’] for Rust.

Implementors§