提交 64d9704b 编写于 作者: D dpoeschl

Bugfix 1086632 [RenameSymbolAsync] throws exception when renaming multiple...

Bugfix 1086632 [RenameSymbolAsync] throws exception when renaming multiple symbols using a solution object / Crash when invoking EncapsulateField on multiple static fields

These exceptions and crashes were happening because rename was leaving annotations on nodes even after the rename operation was complete. The ConflictEngine already had a method to RemoveAllRenameAnnotations, but it failed to remove annotated nodes or tokens nested inside other annotated nodes.

This change updates RemoveAllRenameAnnotations's call to SyntaxNode.ReplaceSyntax to use computeReplacementNode & computeReplacementToken functions that utilize the "updated" node instead of the "original" node when calculating their replacements, which then preserves any earlier changes to descendant nodes/tokens. (changeset 1406014)
上级 1e813498
......@@ -67,12 +67,15 @@ internal void RemoveAllRenameAnnotations(IEnumerable<DocumentId> documentWithRen
{
var document = newSolution.GetDocument(documentId);
var root = document.GetSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken);
// For the computeReplacementToken and computeReplacementNode functions, use
// the "updated" node to maintain any annotation removals from descendants.
var newRoot = root.ReplaceSyntax(
annotationSet.GetAnnotatedNodes(root),
(original, dummy) => annotationSet.WithoutAnnotations(original, annotationSet.GetAnnotations(original).ToArray()),
annotationSet.GetAnnotatedTokens(root),
(original, dummy) => annotationSet.WithoutAnnotations(original, annotationSet.GetAnnotations(original).ToArray()),
SpecializedCollections.EmptyEnumerable<SyntaxTrivia>(),
nodes: annotationSet.GetAnnotatedNodes(root),
computeReplacementNode: (original, updated) => annotationSet.WithoutAnnotations(updated, annotationSet.GetAnnotations(updated).ToArray()),
tokens: annotationSet.GetAnnotatedTokens(root),
computeReplacementToken: (original, updated) => annotationSet.WithoutAnnotations(updated, annotationSet.GetAnnotations(updated).ToArray()),
trivia: SpecializedCollections.EmptyEnumerable<SyntaxTrivia>(),
computeReplacementTrivia: null);
this.intermediateSolutionContainingOnlyModifiedDocuments = this.intermediateSolutionContainingOnlyModifiedDocuments.WithDocumentSyntaxRoot(documentId, newRoot, PreservationMode.PreserveIdentity);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册