/// <summary>Calculates the position, the caret should be set to, after the /// code fix was applied.</summary> /// <param name="changedSolution">The changed solution (code fix applied).</param> /// <param name="originalDocument">The original document (code fix not applied).</param> /// <param name="diagnostic">The diagnosted code fix.</param> /// <param name="cancellationToken">A cancellation token to cancel the calculation.</param> /// <returns>The position , the caret should be set to, after the code fix /// was applied. Null if the caret should not be moved.</returns> private static async Task <NavigationTarget> CalculateNavigationTarget(Solution changedSolution, Document originalDocument, Diagnostic diagnostic, CancellationToken cancellationToken) { MemberDeclarationSyntax originalDeclaration; MemberDeclarationSyntax changedDeclaration; SyntaxNode originalSyntaxRoot; SyntaxNode changedSyntaxRoot; Document changedDocument; int targetPosition; NavigationTarget result = null; // Get syntax root of the original document originalSyntaxRoot = await originalDocument.GetSyntaxRootAsync(cancellationToken) .ConfigureAwait(false); // Get the original declaration that was diagnosted originalDeclaration = originalSyntaxRoot.FindToken(diagnostic.Location.SourceSpan.Start) .Parent .AncestorsAndSelf() .OfType <MemberDeclarationSyntax>() .First(); // Get the changed document changedDocument = changedSolution.GetDocument(originalDocument.Id); // Get syntax root of the changed document changedSyntaxRoot = await changedDocument.GetSyntaxRootAsync(cancellationToken) .ConfigureAwait(false); // Find declaration in changed document changedDeclaration = changedSyntaxRoot.DescendantNodes() .OfType <MemberDeclarationSyntax>() .FirstOrDefault(newNode => SyntaxFactory.AreEquivalent(newNode, originalDeclaration)); // Get the target position in the the XML documentation header of the // changed declaration inside the changed document targetPosition = DocumentationHelper.GetPositionOfFirstEmptyDocumentationTag(changedDeclaration); // targetPosition is less than zero if no empty documentation tag was found. if (targetPosition > 0) { result = new NavigationTarget(changedDocument.Id, targetPosition); } return(result); }