简体   繁体   中英

Multiple Completion Providers in VSCode Extension

I have an VSCode extension that connects to a remote language server and then registers a new CompletionItemProvider .

The thing is that my solution doesn't seem to work properly. The following code results in the completions only from the last line ( itemsCompletion ) and doesn't include any completions from the LSP.

if (isOpenHABWorkspace()) {
    disposables.push(window.registerTreeDataProvider('openhabItems', itemsExplorer))
    if (hasExtension('misc-lsp')) {
        let languageClientProvider = new LanguageClientProvider()
        disposables.push(languageClientProvider.connect())
    }
    const itemsCompletion = new ItemsCompletion(getHost())
    disposables.push(languages.registerCompletionItemProvider('openhab', itemsCompletion))
}

However if I comment the last two lines out, the completions come from LSP perfectly. In this case I'd like to keep both of completions sources.

Can't wrap my head around this, I'd appreciate any help. :) Cheers

It is hard to tell what is causing this problem just from looking at the code you posted, however I may have some information that might help you out.

What is registering the completion provider? The extension itself or the language server?

I ask you this because language servers do not usually deal with vscode providers. You can implement code completion with a completion provider which is registered on the extension and has nothing to do with the language server or you can respond to the onCompletion request in the server and send the items back to the extension. Usually one of these methods is used but you can of course use both, just know that they will be working separately.

You can see here that you can choose the Language Server Protocol or direct implementation (providers). I think you may be mixing both of them.

If what you are missing is the completions from the language server, make sure you have declared item completion on the server capabilities.

{
...
"capabilities" : {
    "completionProvider" : {
        "resolveProvider": "true",
        "triggerCharacters": [ '.' ]
    }
    ...
}
}

Also, make sure you are responding to the completion request with the correct data structure, which should be a list of completionItems. You can read more about that here in the LSP specification.

Hope this helps you at least a bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM