public static async Task <Document> RefactorAsync( Document document, DocumentationCommentTriviaSyntax documentationComment, CancellationToken cancellationToken) { XmlElementSyntax summaryElement = documentationComment.SummaryElement(); if (summaryElement == null) { SyntaxList <XmlNodeSyntax> content = documentationComment.Content; SourceText text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); TextLine line = text.Lines[documentationComment.GetFullSpanStartLine(cancellationToken)]; string indent = StringUtility.GetIndent(line.ToString()); string newText = CreateSummaryElement(indent); var textChange = new TextChange(new TextSpan(documentationComment.FullSpan.Start, 0), newText); return(await document.WithTextChangeAsync(textChange).ConfigureAwait(false)); } Debug.Assert(false, ""); return(document); }
private static async Task <Document> FormatSummaryOnSingleLineAsync( Document document, DocumentationCommentTriviaSyntax documentationComment, CancellationToken cancellationToken) { SourceText sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); XmlElementSyntax summaryElement = documentationComment.SummaryElement(); XmlElementStartTagSyntax startTag = summaryElement.StartTag; XmlElementEndTagSyntax endTag = summaryElement.EndTag; Match match = _formatSummaryOnSingleLineRegex.Match( summaryElement.ToString(), startTag.Span.End - summaryElement.SpanStart, endTag.SpanStart - 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)); }
public static void Analyze(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentationComment) { XmlElementSyntax summaryElement = documentationComment.SummaryElement(); 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); } } } } }
public static void Analyze(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentationComment) { XmlElementSyntax summaryElement = documentationComment.SummaryElement(); if (summaryElement?.StartTag?.IsMissing == false && summaryElement.EndTag?.IsMissing == false && summaryElement.IsSingleLine(includeExteriorTrivia: false, trim: false)) { context.ReportDiagnostic( DiagnosticDescriptors.FormatDocumentationSummaryOnMultipleLines, summaryElement); } }
private static async Task <Document> FormatSummaryOnMultipleLinesAsync( Document document, DocumentationCommentTriviaSyntax documentationComment, CancellationToken cancellationToken) { SourceText sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); XmlElementSyntax summaryElement = documentationComment.SummaryElement(); string indentation = ""; SyntaxTrivia parentTrivia = documentationComment.ParentTrivia; SyntaxToken token = parentTrivia.Token; SyntaxTriviaList leadingTrivia = token.LeadingTrivia; int index = leadingTrivia.IndexOf(parentTrivia); if (index > 0) { SyntaxTrivia previousTrivia = token.LeadingTrivia[index - 1]; if (previousTrivia.IsWhitespaceTrivia()) { indentation = previousTrivia.ToString(); } } string endOfLine = documentationComment.DescendantTokens().FirstOrDefault(f => f.IsKind(SyntaxKind.XmlTextLiteralNewLineToken)).ToString(); if (endOfLine.Length == 0) { endOfLine = Environment.NewLine; } string startOfLine = endOfLine + indentation + "/// "; SourceText newSourceText = sourceText.WithChanges( new TextChange(new TextSpan(summaryElement.StartTag.Span.End, 0), startOfLine), new TextChange(new TextSpan(summaryElement.EndTag.SpanStart, 0), startOfLine)); return(document.WithText(newSourceText)); }
public static void Analyze(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentationComment) { XmlElementSyntax summaryElement = documentationComment.SummaryElement(); if (summaryElement != null) { if (IsSummaryMissing(summaryElement)) { context.ReportDiagnostic( DiagnosticDescriptors.AddSummaryToDocumentationComment, summaryElement); } } else { context.ReportDiagnostic( DiagnosticDescriptors.AddSummaryElementToDocumentationComment, documentationComment); } }
private static Task <Document> FormatSummaryOnSingleLineAsync( Document document, DocumentationCommentTriviaSyntax documentationComment, CancellationToken cancellationToken) { XmlElementSyntax summaryElement = documentationComment.SummaryElement(); XmlElementStartTagSyntax startTag = summaryElement.StartTag; XmlElementEndTagSyntax endTag = summaryElement.EndTag; Match match = _formatSummaryOnSingleLineRegex.Match( summaryElement.ToString(), startTag.Span.End - summaryElement.SpanStart, endTag.SpanStart - startTag.Span.End); return(document.WithTextChangeAsync( new TextSpan(startTag.Span.End, match.Length), match.Groups[1].Value, cancellationToken)); }
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 = documentationComment.SummaryElement(); 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)); }