1

I am working on a VsCode extension in that I want to provide custom snippets for code completion.

I know about the option of using snippet json files directly, however those have the limitation of not being able to utilize the CompletionItemKind property that determines the icon next to the completion suggestion in the pop-up.

My issue:

If I implement a simple CompletionItemProvider like this:

context.subscriptions.push(
    vscode.languages.registerCompletionItemProvider(
        {scheme:"file",language:"MyLang"},  
        {
            provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
                let item = new vscode.CompletionItem('test');
                item.documentation = 'my test function';
                item.kind = vscode.CompletionItemKind.Function;
                return [item];
            }
        }
    )
)

then the original VsCode IntelliSense text suggestions are not shown anymore, only my own. Should I just return a kind of an empty response, like

provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {
    return [null|[]|undefined];
}

the suggestions appear again as they should. It seems to me that instead of merging the results of the built-in IntelliSense and my own provider, the built-in ones get simply overridden.

Question:

How can I keep the built-in IntelliSense suggestions while applying my own CompletionItems?

VsCode Version: v1.68.1 Ubuntu

elod008
  • 1,227
  • 1
  • 5
  • 15

1 Answers1

1

I seem to have found the answer for my problem, so I will answer my question.

Multiple providers can be registered for a language. In that case providers are sorted
by their {@link languages.match score} and groups of equal score are sequentially asked for
completion items. The process stops when one or many providers of a group return a
result.

My provider seems to provide results that are just higher scored than those of IntelliSense.
Since I didn't provide any trigger characters, my CompletionItems were comteping directly with the words found by the built-in system by every single pressed key and won.

My solution is to simply parse and register the words in my TextDocument myself and extend my provider results by them. I could probably just as well create and register a new CompletionItemProvider for them if I wanted to, however I decided to have a different structure for my project.

elod008
  • 1,227
  • 1
  • 5
  • 15