显示基于单词的建议和自己的完成提供程序的结果 [英] Show results from both word based suggestions and own completion provider

查看:27
本文介绍了显示基于单词的建议和自己的完成提供程序的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Visual Studio Code 扩展,它使用语言服务器协议提供一个完成列表.我的问题是,实施后,用户根据文档内容丢失了完成.

我希望完成显示我自己的提供者的结果以及 VSCode 基于单词的建议.

非工作示例:

工作示例:

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

我尝试将 isIncomplete 设置为 false,但没有任何改进.

解决方案

这是 VSCode 的一项功能,称为基于单词的建议";(请参阅 editor.wordBasedSuggestions" 设置).当所有其他注册完成提供程序未能返回任何结果时,默认情况下会提供基于单词的建议.

我不知道有什么方法可以将基于文字的建议与您自己的提供商的结果合并.VSCode 开发人员的声明 似乎证实了这不是可能:

<块引用><块引用>

即使有完成提供程序返回建议,为什么不包括基于字符串的匹配?

每个提供商都会获得一个a> 取决于它在注册时使用的选择器.基于词的提供者通常得分最低,CompletionItemKind.Text,它应该看起来与 VSCode 的内置提供程序相同.我假设要提供完成,您无论如何都必须扫描文档内容.作为一个额外的好处,这可以避免出现问题中提到的重复.


可能相关的问题:#21611

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.

解决方案

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.


Possibly related issue: #21611

这篇关于显示基于单词的建议和自己的完成提供程序的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆