Skip to content

Latest commit

 

History

History
145 lines (71 loc) · 3.14 KB

File metadata and controls

145 lines (71 loc) · 3.14 KB
description
The completion provider interface defines how extensions should communicate code completion suggestions in CodeEdit.

CompletionProvider

Registering a Completion Provider

codeedit.extensions.registerCompletionProvider(myCompletionProvider)

CompletionProvider Interface

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 %}

CompletionItem

Constructor

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.

Properties

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.

range?: Range | {inserting: Range, replacing: Range}
sortText?: string

CompletionItemKind