Beispiel #1
0
        private static Document InsertInheritdocComment(Document document, SyntaxNode root, SyntaxNode syntaxNode, CancellationToken cancellationToken)
        {
            // Currently unused
            _ = cancellationToken;

            SyntaxTriviaList leadingTrivia = syntaxNode.GetLeadingTrivia();
            int insertionIndex             = leadingTrivia.Count;

            while (insertionIndex > 0 && !leadingTrivia[insertionIndex - 1].HasBuiltinEndLine())
            {
                insertionIndex--;
            }

            string newLineText          = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.NewLine, LanguageNames.CSharp);
            var    documentationComment =
                XmlSyntaxFactory.DocumentationComment(
                    newLineText,
                    XmlSyntaxFactory.EmptyElement(XmlCommentHelper.InheritdocXmlTag));
            var trivia = SyntaxFactory.Trivia(documentationComment);

            SyntaxTriviaList newLeadingTrivia = leadingTrivia.Insert(insertionIndex, trivia);
            SyntaxNode       newElement       = syntaxNode.WithLeadingTrivia(newLeadingTrivia);

            return(document.WithSyntaxRoot(root.ReplaceNode(syntaxNode, newElement)));
        }
Beispiel #2
0
        private static async Task <Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
        {
            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            var xmlElement = (XmlElementSyntax)root.FindNode(diagnostic.Location.SourceSpan, findInsideTrivia: true, getInnermostNodeForTie: true);

            var newXmlElement = XmlSyntaxFactory.EmptyElement(XmlCommentHelper.SeeXmlTag)
                                .AddAttributes(XmlSyntaxFactory.TextAttribute("langword", xmlElement.Content.ToFullString()))
                                .WithTriviaFrom(xmlElement);

            return(document.WithSyntaxRoot(root.ReplaceNode(xmlElement, newXmlElement)));
        }