我在看罗斯林的 CompletionService
, 和 ShouldTriggerCompletion
定义为
public virtual bool ShouldTriggerCompletion(
SourceText text,
int caretPosition,
CompletionTrigger trigger,
ImmutableHashSet<string> roles = null,
OptionSet options = null
) { … }
在哪里
CompletionTrigger
是单个 char Character
的包装器.这似乎暗示我应该调用
ShouldTriggerCompletion
键入时在每个字符上 — 但这意味着我需要更新 SourceText
在每个字符上,它分配一个数组 TextChange
, 一个新的 SourceText
可能还有其他取决于其内部结构的东西。我是否正确理解了这个 API?打字时最有效的使用方法是什么?
编辑:澄清一下,我知道我可以猜测它并且只调用它让我们说
.
.但我的目标是按照预期的方式使用 API,除了已经提供的优化之外,没有任何优化。
最佳答案
however that would mean I need to update SourceText on each char, which allocates an array of TextChange, a new SourceText and potentially other things depending on its internal structure
是的,在 Visual Studio 中的每次击键时,我们都会创建一个新的 SourceText 和一个新的文档/项目/解决方案快照。我们必须这样做,因为所有功能都取决于现有的 Document 实例。
对我们来说,这样的手术很便宜。 Visual Studio 中的文本编辑器组件已经创建了一个廉价的
ITextSnapshot
对于每个编辑,它通过非常奇特的数据结构(想想字符串的二叉树)进行,所以它尽可能便宜。当我们在编辑器中为文件创建 SourceTexts 时,我们改为创建 own derived type of SourceText我们只是将数据请求转发给编辑ITextSnapshot
API。 SourceText 实际上具有 ITextSnapshot
的子集并非巧合。的成员,因为我们正是为这种模式设计的!
关于.net - 打字时使用 Roslyn 的 CompletionSevice 最有效的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39421668/