1

So I'm using Roslyn to generate intellisense results for a solution with many files, and I need to update the document every key press. Creating the sourcetext instance and the new solution takes very little time, but calling workspace.TryApplyChanges takes around 500ms per key press, which is too much for me. Am I doing this wrong? (I just want to generate completion results from the workspace through CompletionService. Here is how I'm updating my workspace:

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);

I am calling the above code EVERY single time the user types. Is there any way to make this quicker? Thanks.

Visual User
  • 69
  • 1
  • 6

1 Answers1

2

OK, I figured it out. It turns out, all you have to do is just update your workspace like this:

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

For some reason this is actually MUCH quicker!

Visual User
  • 69
  • 1
  • 6