停止智能感知会话过早关闭

Stop intellisense session from closing prematurely

我创建了一个 Visual Studio 扩展,它通过继承 Microsoft.VisualStudio.Language.Intellisense.ICompletionSource 为我的领域特定语言提供智能感知。

这工作正常,除了我的语言的关键字中的有效字符是下划线“_”。

当 intellisense 弹出时,您可以开始输入,并且 intellisense 框的内容会被过滤以仅显示以您输入的内容开头的项目。

但是,如果用户键入下划线,这似乎以特殊方式处理,而不是继续过滤可用智能感知项目列表,它提交当前项目并结束智能感知会话。

有没有办法阻止这种行为,以便将下划线视为与常规字母数字字符相同?

If you go into Tools->Options->Text Editor->JavaScript->IntelliSense->References there should be a drop down for the reference group (depending on what type of project you may need to change this)

Once you have the right group you'll noticed there are some default included intellisense reference files. Try removing the underscorefilter.js

找到这个 here。让我知道这是否适合你。

我不确定你使用的是什么语言,但在你的 Exec 方法中,听起来你正在做类似 (c#):

的事情
if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN || nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB || (char.IsWhiteSpace(typedChar) || char.IsPunctuation(typedChar))

这里的原因是 _ 被认为是标点符号,所以 char.IsPunctuation(typedChar) returns 正确,提交当前项目。

修复 - (char.IsPunctuation(typedChar) && typedChar != '_'):

if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN || nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB || (char.IsWhiteSpace(typedChar) || (char.IsPunctuation(typedChar) && typedChar != '_') || typedChar == '='))

仅供参考:我已经通过调试此扩展进行了测试 - https://github.com/kfmaurice/nla。如果没有此更改,它也会在键入下划线时提交。

visual studio 使用了 插件链 ,并且其他一些插件在您的插件之前处理下划线。试试 destructi6n.

的建议