description |
---|
The completion provider interface defines how extensions should communicate code completion suggestions in CodeEdit. |
codeedit.extensions.registerCompletionProvider(myCompletionProvider)
class CompletionProvider {
provideCompletionItems(editor, context) {
...
return completionItems;
}
}
It is expected that every CompletionProvider
class include a provideCompletionItems
method, the role of which is to return an array of CompletionItem
objects. This array of objects is used to determine relevant completion suggestions as the user types inside the editor.
In the case of the CompletionProvider
, the provideCompletionItems
method will be called each time the user types in the editor while the activation event conditions are met. CodeEdit will then determine the relevant suggestions.
The provideCompletionItems
method expects an editor and context as arguments. These objects provide the extension with information about the state when a completion is triggered, including the scope of the current cursor position.
{% hint style="info" %} Using the context object, additional completion criteria can be defined by limiting the results returned by the provideCompletionItems method based on the current context. For example, a completion suggestion that is a CSS class name, should only be returned when the current context is within a valid HTML class attribute. {% endhint %}
new CompletionItem(label: string, kind?:
CompletionItemKind
): CompletionItem
Instantiates a new completion item object.
Completion items must have a label that is used as the default insert text as well as for sorting and filtering of completion suggestions.
additionalTextEdits?: TextEdit[]
An array of additional text edits that should be applied when the completion is selected. Edits must not overlap.
command?: Command
A command that should be executed after insertion of the selected completion.
commitCharacters?: string[]
detail?: string
documentation?: string | MarkdownString
filterText?: string
insertText?: string
keepWhitespace?: boolean
kind?: CompletionItemKind
label: string
The label of the completion item. It is also the default text that is inserted if the insertText property is not set.