Search code examples
intellisensevscode-extensionsautosuggest

add completionitemprovider and keep suggestions


I created a completionitemprovider for my extension, but now the suggestions based on words in the document aren't shown. Do I have to provide each word in the document?

export class ScriptViewProvider implements vscode.CompletionItemProvider
...
    extension.context.subscriptions.push(vscode.languages.registerCompletionItemProvider(
            ["language"],
            this));
...
    async provideCompletionItems(document : vscode.TextDocument, position : vscode.Position) : Promise<vscode.CompletionItem[]> {
        let completions : vscode.CompletionItem[] = [];
        let completion = new vscode.CompletionItem("bla", vscode.CompletionItemKind.Field);
        completions.push(completion);
        return completions;
    }

It brings up "bla" when I type "b", but none of the other words in the document appear.


Solution

  • See this comment of an open VS Code issue.

    When your CompletionProvider was registered using a DocumentSelector that is more significant than that of other providers and returns at least one completion item, the other providers are skipped. The word-based suggestions provider is less significant and so it does not contribute any suggestions.

    Depending on the nature of your extension you could try to define a less specific DocumentSelector when registering your CompletionProvider. If this is not possible I think there is no other option than to providing all completion items yourself (including word-based suggestions).