Exemple #1
0
        public static async Task <Document> RefactorAsync(
            Document document,
            DocumentationCommentTriviaSyntax documentationComment,
            CancellationToken cancellationToken)
        {
            SourceText sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

            XmlElementSyntax summaryElement = FormatSummaryRefactoring.GetSummaryElement(documentationComment);

            XmlElementStartTagSyntax startTag = summaryElement.StartTag;
            XmlElementEndTagSyntax   endTag   = summaryElement.EndTag;

            Match match = FormatSummaryRefactoring.Regex.Match(
                summaryElement.ToString(),
                startTag.Span.End - summaryElement.Span.Start,
                endTag.Span.Start - startTag.Span.End);

            var textChange = new TextChange(
                new TextSpan(startTag.Span.End, match.Length),
                match.Groups[1].Value);

            SourceText newSourceText = sourceText.WithChanges(textChange);

            return(document.WithText(newSourceText));
        }
Exemple #2
0
        public static void Analyze(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentationComment)
        {
            XmlElementSyntax summaryElement = FormatSummaryRefactoring.GetSummaryElement(documentationComment);

            if (summaryElement != null)
            {
                XmlElementStartTagSyntax startTag = summaryElement?.StartTag;

                if (startTag?.IsMissing == false)
                {
                    XmlElementEndTagSyntax endTag = summaryElement.EndTag;

                    if (endTag?.IsMissing == false &&
                        startTag.GetSpanEndLine() < endTag.GetSpanStartLine())
                    {
                        Match match = FormatSummaryRefactoring.Regex.Match(
                            summaryElement.ToString(),
                            startTag.Span.End - summaryElement.Span.Start,
                            endTag.Span.Start - startTag.Span.End);

                        if (match.Success)
                        {
                            context.ReportDiagnostic(
                                DiagnosticDescriptors.FormatDocumentationSummaryOnSingleLine,
                                summaryElement.GetLocation());
                        }
                    }
                }
            }
        }
        public static void Analyze(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentationComment)
        {
            XmlElementSyntax summaryElement = FormatSummaryRefactoring.GetSummaryElement(documentationComment);

            if (summaryElement?.StartTag?.IsMissing == false &&
                summaryElement.EndTag?.IsMissing == false &&
                summaryElement.IsSingleLine(includeExteriorTrivia: false, trim: false))
            {
                context.ReportDiagnostic(
                    DiagnosticDescriptors.FormatDocumentationSummaryOnMultipleLines,
                    summaryElement.GetLocation());
            }
        }
        public static async Task <Document> RefactorAsync(
            Document document,
            DocumentationCommentTriviaSyntax documentationComment,
            CancellationToken cancellationToken)
        {
            SourceText sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

            int lineIndex = documentationComment.GetSpanStartLine(cancellationToken);

            XmlElementSyntax summaryElement = FormatSummaryRefactoring.GetSummaryElement(documentationComment);

            string newText = Environment.NewLine
                             + new string(' ', documentationComment.FullSpan.Start - sourceText.Lines[lineIndex].Start)
                             + "/// ";

            SourceText newSourceText = sourceText.WithChanges(
                new TextChange(new TextSpan(summaryElement.StartTag.Span.End, 0), newText),
                new TextChange(new TextSpan(summaryElement.EndTag.Span.Start, 0), newText));

            return(document.WithText(newSourceText));
        }