Beispiel #1
0
        private async Task <Solution> UpdateDocumentsAsync(Solution solution, SyntaxNodeReplacementPair invocation, SyntaxNodeReplacementPair declaration, CancellationToken cancellationToken)
        {
            if (AreTheSameDocuments(invocation.Document, declaration.Document))
            {
                try
                {
                    SyntaxNode root = invocation.Root.ReplaceNode(invocation.OriginalNode, invocation.ReplacementNode);

                    SyntaxNode found = root.FindNode(declaration.OriginalNode.Span);
                    root = root.ReplaceNode(found, declaration.ReplacementNode);

                    solution = solution.WithDocumentSyntaxRoot(declaration.Document.Id, root);
                }
                catch
                {
                    // TODO: add loging or improve logic to be sure that exception never occure
                }
            }
            else
            {
                solution = await ReplaceAndSimplifyNodeAsync(solution, invocation, cancellationToken)
                           .ConfigureAwait(false);

                solution = await ReplaceAndSimplifyNodeAsync(solution, declaration, cancellationToken)
                           .ConfigureAwait(false);
            }

            return(solution);
        }
Beispiel #2
0
        private async Task <Solution> ReplaceAndSimplifyNodeAsync(Solution solution, SyntaxNodeReplacementPair pair, CancellationToken cancellationToken)
        {
            SyntaxNode node = pair.Root.ReplaceNode(pair.OriginalNode, pair.ReplacementNode.WithAdditionalAnnotations(Simplifier.Annotation));

            node = await SimplifyAsync(solution, pair.Document.Id, node, cancellationToken).ConfigureAwait(false);

            return(solution.WithDocumentSyntaxRoot(pair.Document.Id, node));
        }
Beispiel #3
0
        protected override async Task <Solution> ChangedSolutionHandlerAsync(Document document, InvocationExpressionSyntax syntaxDeclaration, CancellationToken cancellationToken)
        {
            SyntaxNodeReplacementPair invocation = await ConstructInvocationPairAsync(document, syntaxDeclaration, cancellationToken)
                                                   .ConfigureAwait(false);

            SyntaxNodeReplacementPair declaration = await ConstructDeclarationPairAsync(document, syntaxDeclaration, cancellationToken)
                                                    .ConfigureAwait(false);

            Solution solution = document.Project.Solution;

            return(await UpdateDocumentsAsync(solution, invocation, declaration, cancellationToken).ConfigureAwait(false));
        }