private LineColumnDelta FormatStructuredTrivia(
            LineColumn lineColumn, SyntaxTrivia trivia, List <SyntaxTrivia> changes, CancellationToken cancellationToken)
        {
            if (trivia.Kind() == SyntaxKind.SkippedTokensTrivia)
            {
                // don't touch anything if it contains skipped tokens
                _succeeded = false;
                changes.Add(trivia);

                return(GetLineColumnDelta(lineColumn, trivia));
            }

            // TODO : make document comment to be formatted by structured trivia formatter as well.
            if (!trivia.IsDocComment())
            {
                var result = CSharpStructuredTriviaFormatEngine.Format(
                    trivia, this.InitialLineColumn.Column, this.OptionSet, this.FormattingRules, cancellationToken);
                var formattedTrivia = SyntaxFactory.Trivia((StructuredTriviaSyntax)result.GetFormattedRoot(cancellationToken));

                changes.Add(formattedTrivia);
                return(GetLineColumnDelta(lineColumn, formattedTrivia));
            }

            var docComment = FormatDocumentComment(lineColumn, trivia);

            changes.Add(docComment);

            return(GetLineColumnDelta(lineColumn, docComment));
        }
Exemple #2
0
        private LineColumnDelta FormatStructuredTrivia(
            LineColumn lineColumn, SyntaxTrivia trivia, ArrayBuilder <TextChange> changes, CancellationToken cancellationToken)
        {
            if (trivia.Kind() == SyntaxKind.SkippedTokensTrivia)
            {
                // don't touch anything if it contains skipped tokens
                _succeeded = false;
                return(GetLineColumnDelta(lineColumn, trivia));
            }

            // TODO : make document comment to be formatted by structured trivia formatter as well.
            if (!trivia.IsDocComment())
            {
                var result = CSharpStructuredTriviaFormatEngine.Format(
                    trivia, this.InitialLineColumn.Column, this.Options, this.FormattingRules, cancellationToken);
                if (result.GetTextChanges(cancellationToken).Count == 0)
                {
                    return(GetLineColumnDelta(lineColumn, trivia));
                }

                changes.AddRange(result.GetTextChanges(cancellationToken));

                var formattedTrivia = SyntaxFactory.Trivia((StructuredTriviaSyntax)result.GetFormattedRoot(cancellationToken));
                return(GetLineColumnDelta(lineColumn, formattedTrivia));
            }

            var docComment = FormatDocumentComment(lineColumn, trivia);

            if (docComment != trivia)
            {
                changes.Add(new TextChange(trivia.FullSpan, docComment.ToFullString()));
            }

            return(GetLineColumnDelta(lineColumn, docComment));
        }
Exemple #3
0
 private void ClassifyTrivia(SyntaxTrivia trivia)
 {
     if (trivia.IsRegularComment())
     {
         AddClassification(trivia, ClassificationTypeNames.Comment);
     }
     else if (trivia.Kind() == SyntaxKind.DisabledTextTrivia)
     {
         AddClassification(trivia, ClassificationTypeNames.ExcludedCode);
     }
     else if (trivia.Kind() == SyntaxKind.SkippedTokensTrivia)
     {
         ClassifySkippedTokens((SkippedTokensTriviaSyntax)trivia.GetStructure());
     }
     else if (trivia.IsDocComment())
     {
         ClassifyDocumentationComment((DocumentationCommentTriviaSyntax)trivia.GetStructure());
     }
     else if (trivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
     {
         AddClassification(trivia, ClassificationTypeNames.XmlDocCommentDelimiter);
     }
     else if (SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
     {
         ClassifyPreprocessorDirective((DirectiveTriviaSyntax)trivia.GetStructure());
     }
 }
Exemple #4
0
 private void ClassifyTrivia(SyntaxTrivia trivia)
 {
     if (trivia.IsRegularComment())
     {
         AddClassification(trivia, ClassificationTypeNames.Comment);
     }
     else if (trivia.Kind() == SyntaxKind.DisabledTextTrivia)
     {
         AddClassification(trivia, ClassificationTypeNames.ExcludedCode);
     }
     else if (trivia.Kind() == SyntaxKind.SkippedTokensTrivia)
     {
         ClassifySkippedTokens((SkippedTokensTriviaSyntax)trivia.GetStructure());
     }
     else if (trivia.IsDocComment())
     {
         ClassifyDocumentationComment((DocumentationCommentTriviaSyntax)trivia.GetStructure());
     }
     else if (trivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
     {
         AddClassification(trivia, ClassificationTypeNames.XmlDocCommentDelimiter);
     }
     else if (SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
     {
         ClassifyPreprocessorDirective((DirectiveTriviaSyntax)trivia.GetStructure());
     }
 }
 public static bool IsRegularOrDocComment(this SyntaxTrivia trivia)
 {
     return(trivia.IsSingleLineComment() || trivia.IsMultiLineComment() || trivia.IsDocComment());
 }
 private static bool IsDocCommentOrElastic(SyntaxTrivia t)
 {
     return(t.IsDocComment() || t.IsElastic());
 }
Exemple #7
0
 public static bool IsRegularOrDocComment(this SyntaxTrivia trivia)
 {
     return(trivia.IsRegularComment() || trivia.IsDocComment());
 }
 public static bool IsRegularOrDocComment(this SyntaxTrivia trivia) =>
 trivia.IsRegularComment() || trivia.IsDocComment();
 protected override bool IsRegularCommentOrDocComment(SyntaxTrivia trivia)
 => trivia.IsRegularComment() || trivia.IsDocComment();
        private LineColumnDelta FormatStructuredTrivia(
            LineColumn lineColumn, SyntaxTrivia trivia, List<TextChange> changes, CancellationToken cancellationToken)
        {
            if (trivia.Kind() == SyntaxKind.SkippedTokensTrivia)
            {
                // don't touch anything if it contains skipped tokens
                _succeeded = false;
                return GetLineColumnDelta(lineColumn, trivia);
            }

            // TODO : make document comment to be formatted by structured trivia formatter as well.
            if (!trivia.IsDocComment())
            {
                var result = CSharpStructuredTriviaFormatEngine.Format(
                    trivia, this.InitialLineColumn.Column, this.OptionSet, this.FormattingRules, cancellationToken);
                if (result.GetTextChanges(cancellationToken).Count == 0)
                {
                    return GetLineColumnDelta(lineColumn, trivia);
                }

                changes.AddRange(result.GetTextChanges(cancellationToken));

                var formattedTrivia = SyntaxFactory.Trivia((StructuredTriviaSyntax)result.GetFormattedRoot(cancellationToken));
                return GetLineColumnDelta(lineColumn, formattedTrivia);
            }

            var docComment = FormatDocumentComment(lineColumn, trivia);
            if (docComment != trivia)
            {
                changes.Add(new TextChange(trivia.FullSpan, docComment.ToFullString()));
            }

            return GetLineColumnDelta(lineColumn, docComment);
        }
 private static bool IsDocCommentOrElastic(SyntaxTrivia t)
 {
     return t.IsDocComment() || t.IsElastic();
 }
 private static bool IsDocCommentOrElastic(SyntaxTrivia t)
 => t.IsDocComment() || t.IsElastic();