更新AdHocWorkspace的速度很慢

问题描述 投票:0回答:1

因此,我正在使用Roslyn生成具有许多文件的解决方案的智能感知结果,并且每次按键时我都需要更新文档。创建源文本实例和新的解决方案只需要很少的时间,但是每次按键调用workspace.TryApplyChanges大约需要500毫秒,这对我来说实在太多了。我做错了吗? (我只想通过CompletionService从工作空间生成完成结果。这是我更新工作空间的方法:

SourceText sourceText = SourceText.From(editorText);
Solution newSolution = solutionDocument.Project.Solution.WithDocumentText(solutionDocument.Id, sourceText);
solutionWorkspace.TryApplyChanges(newSolution); //Every other part is pretty quick, except this.
solutionDocument = solutionWorkspace.CurrentSolution.GetDocument(solutionDocument.Id);

我每次用户键入时都会调用上面的代码。有什么方法可以使它更快?谢谢。

c# .net intellisense roslyn
1个回答
0
投票

好,我知道了。事实证明,您要做的就是像这样更新您的工作空间:

solutionWorkspace.TryApplyChanges(solutionDocument.WithText(SourceText.From(editorText)).Project.Solution);

由于某种原因,这实际上要快得多!

© www.soinside.com 2019 - 2024. All rights reserved.