Show results from both word based suggestions and own completion provider

最后都变了- 提交于 2019-12-12 18:51:15

问题


I am developing a Visual Studio Code extension, that, using the Language Server Protocol, provides a completion list. My problem is that after implementing it, users have lost the completion based on the document contents.

I want completion to show both my own provider's results as well as VSCode's word based suggestions.

Non-Working example:

Working example:

(https://github.com/APerricone/harbourCodeExtension/issues/16)

I tried to set isIncomplete to false, without any improvement.


回答1:


This is a VSCode feature called "word-based suggestions" (see the "editor.wordBasedSuggestions" setting). Word based suggestions are by default provided whenever all other registered completion providers fail to return any results.

I'm not aware of any way to have word-based suggestions be merged with your own provider's results instead. This statement by a VSCode dev seems to confirm that this isn't possible:

Why not include string based matching even when there is a completion provider returning suggestions?

Each provider gets a rank depending on the selector it uses when registering. The word based provider usually has the lowest score and the rule is that lower ranked providers aren't asked if higher ranked providers produced a result. That is to avoid duplicates and spam.

The doc comment of registerCompletionItemProvider() is still the same, so I don't think anything has changed in this regard since then. Perhaps you could open a feature request for this, but I'm not sure how high the chances of it being implemented are.

However, there is a simple workaround: just implement word-based suggestions yourself. If you use CompletionItemKind.Text, it should look the same as VSCode's built-in provider. I assume that to provide completion, you already have to scan the document contents anyway. As an added bonus, this allows avoiding duplicates like mentioned in the issue.



来源:https://stackoverflow.com/questions/55219025/show-results-from-both-word-based-suggestions-and-own-completion-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!