停止intellisense会话提前结束

Sco*_*ham 10 languageservice visual-studio-extensions visual-studio-2015

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

除了我的语言的关键字中的有效字符是下划线'_'之外,这样做没问题.

当intellisense弹出打开时,您可以开始输入并且智能感知框的内容将被过滤,以显示那些以您键入的内容开头的项目.

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

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

K S*_*ett 4

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

if (nCmdID == (uint)VSConstants.VSStd2KCmdID.RETURN || nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB || (char.IsWhiteSpace(typedChar) || char.IsPunctuation(typedChar))
Run Code Online (Sandbox Code Playgroud)

这里的原因是它_被认为是标点符号,因此char.IsPunctuation(typedChar)返回 true,提交当前项目。

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

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

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