Show results from both word based suggestions and

2019-07-10 04:31发布

问题:

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.