Overview
Completions are retrieved in two steps:- Get completion list with
getCompletionsAtPosition()- Fast, returns basic info - Get entry details with
getCompletionEntryDetails()- Slower, called when user selects an item
getCompletionsAtPosition
Returns completion suggestions at a specific position in a file.Signature
Parameters
The path to the source file.
Zero-based character offset in the file where completions are requested.
Options controlling what completions to return:
Formatting options for generated code in completions.
Return Value
CompletionEntry
Example: Basic Completions
Basic Usage
Example: Auto-Import Completions
Auto-Import
Example: Member Completions
Member Completions
getCompletionEntryDetails
Retrieve detailed information about a specific completion entry.Signature
Parameters
The path to the source file.
Position where the completion was requested.
The
name field from the CompletionEntry.Formatting settings for code generation.
The
source field from the CompletionEntry (for auto-imports).User preferences for code generation.
The
data field from the CompletionEntry.Return Value
Example: Completion Details
Completion Details
Completion Triggers
Completions can be triggered by specific characters:Trigger Examples
Sort Text and Ordering
ThesortText field controls display order:
Example: Filtering Completions
Filter by Kind
Commit Characters
Characters that accept/commit a completion:Usage
Performance Optimization
The completions API is optimized for responsiveness:Incomplete Completions
Whenoptions.allowIncompleteCompletions is true, the Language Service may return partial results:
Module Specifier Resolution
Real-World Integration
Complete Example
See Also
Language Service API
Main Language Service reference
Diagnostics
Error reporting and diagnostics
Navigation
Go to definition and find references
Language Service Overview
Language Service architecture