pub trait CompletionProvider {
// Required methods
fn completions(
&self,
text: &Rope,
offset: usize,
trigger: CompletionContext,
window: &mut Window,
cx: &mut Context<'_, InputState>,
) -> Task<Result<CompletionResponse>>;
fn is_completion_trigger(
&self,
offset: usize,
new_text: &str,
cx: &mut Context<'_, InputState>,
) -> bool;
// Provided methods
fn inline_completion(
&self,
_rope: &Rope,
_offset: usize,
_trigger: InlineCompletionContext,
_window: &mut Window,
_cx: &mut Context<'_, InputState>,
) -> Task<Result<InlineCompletionResponse>> { ... }
fn inline_completion_debounce(&self) -> Duration { ... }
fn resolve_completions(
&self,
_completion_indices: Vec<usize>,
_completions: Rc<RefCell<Box<[Completion]>>>,
_: &mut Context<'_, InputState>,
) -> Task<Result<bool>> { ... }
}Expand description
A trait for providing code completions based on the current input state and context.
Required Methods§
Sourcefn completions(
&self,
text: &Rope,
offset: usize,
trigger: CompletionContext,
window: &mut Window,
cx: &mut Context<'_, InputState>,
) -> Task<Result<CompletionResponse>>
fn completions( &self, text: &Rope, offset: usize, trigger: CompletionContext, window: &mut Window, cx: &mut Context<'_, InputState>, ) -> Task<Result<CompletionResponse>>
Fetches completions based on the given byte offset.
- The
offsetis in bytes of current cursor.
textDocument/completion
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion
Sourcefn is_completion_trigger(
&self,
offset: usize,
new_text: &str,
cx: &mut Context<'_, InputState>,
) -> bool
fn is_completion_trigger( &self, offset: usize, new_text: &str, cx: &mut Context<'_, InputState>, ) -> bool
Determines if the completion should be triggered based on the given byte offset.
This is called on the main thread.
Provided Methods§
Sourcefn inline_completion(
&self,
_rope: &Rope,
_offset: usize,
_trigger: InlineCompletionContext,
_window: &mut Window,
_cx: &mut Context<'_, InputState>,
) -> Task<Result<InlineCompletionResponse>>
fn inline_completion( &self, _rope: &Rope, _offset: usize, _trigger: InlineCompletionContext, _window: &mut Window, _cx: &mut Context<'_, InputState>, ) -> Task<Result<InlineCompletionResponse>>
Fetches an inline completion suggestion for the given position.
This is called after a debounce period when the user stops typing. The provider can analyze the text and cursor position to determine what inline completion suggestion to show.
§Arguments
rope- The current text contentoffset- The cursor position in bytes
textDocument/inlineCompletion
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_inlineCompletion
Sourcefn inline_completion_debounce(&self) -> Duration
fn inline_completion_debounce(&self) -> Duration
Returns the debounce duration for inline completions.
Default: 300ms