Hi,
Usually, the code action's GetEdit method looks like below:
public CodeActionEdit GetEdit(CancellationToken cancellationToken) { // Do some stuff to build up newRoot out of document root return new CodeActionEdit(document.UpdateSyntaxRoot(newRoot)); }
The CodeActionEdit constructor expects new IDocument, IProject or ISolution to be passed as an argument. The "newRoot" variable above is of type SyntaxNode. Do I really need to invoke .UpdateSyntaxRoot method to get new IDocument? Isn't the IDocument automatically created over and over again each time a single change is applied to any of the nodes of SyntaxTree? If so, how can I access the newly created IDocument from the level of newRoot reference (is there a field that points at the associated IDocument) ?
So the question is, is there new IDocument instance each time a change takes place in tree (using trivial ReplaceNode method on any of SyntaxNodes), and can the return statement be replaced with something like this:
return new CodeActionEdit(newRoot.ParentDocument);
My second question is can I apply multiple changes using document.UpdateSyntaxRoot(), and return the final form of the tree and Roslyn will be able to properly find the modified nodes, or am I limited to use this statement only once (on original document)?