예제 #1
0
        protected override LineColumnRule GetLineColumnRuleBetween(SyntaxTrivia trivia1, LineColumnDelta existingWhitespaceBetween, bool implicitLineBreak, SyntaxTrivia trivia2)
        {
            if (IsStartOrEndOfFile(trivia1, trivia2))
            {
                return(LineColumnRule.PreserveLinesWithAbsoluteIndentation(lines: 0, indentation: 0));
            }

            // [trivia] [whitespace] [token] case
            if (trivia2.IsKind(SyntaxKind.None))
            {
                var insertNewLine = this.FormattingRules.GetAdjustNewLinesOperation(this.Token1, this.Token2) != null;

                if (IsMultilineComment(trivia1))
                {
                    return(LineColumnRule.PreserveLinesWithGivenIndentation(lines: insertNewLine ? 1 : 0));
                }

                if (insertNewLine)
                {
                    return(LineColumnRule.PreserveLinesWithDefaultIndentation(lines: 0));
                }

                if (existingWhitespaceBetween.Lines > 0 && existingWhitespaceBetween.Spaces != this.Spaces)
                {
                    return(LineColumnRule.PreserveWithGivenSpaces(spaces: this.Spaces));
                }

                return(LineColumnRule.Preserve);
            }

            // preprocessor case
            if (SyntaxFacts.IsPreprocessorDirective(trivia2.Kind()))
            {
                // Check for immovable preprocessor directives, which are bad directive trivia
                // without a preceding line break
                if (trivia2.IsKind(SyntaxKind.BadDirectiveTrivia) && existingWhitespaceBetween.Lines == 0 && !implicitLineBreak)
                {
                    _succeeded = false;
                    return(LineColumnRule.Preserve);
                }

                // if current line is the first line of the file, don't put extra line 1
                var lines = (trivia1.IsKind(SyntaxKind.None) && this.Token1.IsKind(SyntaxKind.None)) ? 0 : 1;

                if (trivia2.IsKind(SyntaxKind.RegionDirectiveTrivia) || trivia2.IsKind(SyntaxKind.EndRegionDirectiveTrivia))
                {
                    return(LineColumnRule.PreserveLinesWithDefaultIndentation(lines));
                }

                return(LineColumnRule.PreserveLinesWithAbsoluteIndentation(lines, indentation: 0));
            }

            // comments case
            if (trivia2.IsRegularOrDocComment())
            {
                // Start of new comments group.
                //
                // 1. Comment groups must contain the same kind of comments
                // 2. Every block comment is a group of its own
                if (!trivia1.IsKind(trivia2.Kind()) || trivia2.IsMultiLineComment() || trivia2.IsMultiLineDocComment() || existingWhitespaceBetween.Lines > 1)
                {
                    if (this.FormattingRules.GetAdjustNewLinesOperation(this.Token1, this.Token2) != null)
                    {
                        return(LineColumnRule.PreserveLinesWithDefaultIndentation(lines: 0));
                    }

                    return(LineColumnRule.PreserveLinesWithGivenIndentation(lines: 0));
                }

                // comments after existing comment
                if (existingWhitespaceBetween.Lines == 0)
                {
                    return(LineColumnRule.PreserveLinesWithGivenIndentation(lines: 0));
                }

                return(LineColumnRule.PreserveLinesWithFollowingPrecedingIndentation);
            }

            if (trivia2.IsKind(SyntaxKind.SkippedTokensTrivia))
            {
                // if there is any skipped tokens, it is not possible to format this trivia range.
                _succeeded = false;
            }

            return(LineColumnRule.Preserve);
        }
 public static bool IsDocComment(this SyntaxTrivia trivia)
 {
     return(trivia.IsSingleLineDocComment() || trivia.IsMultiLineDocComment());
 }
예제 #3
0
 private static bool IsMultilineComment(SyntaxTrivia trivia1)
 => trivia1.IsMultiLineComment() || trivia1.IsMultiLineDocComment();
 protected override bool IsMultilineComment(SyntaxTrivia trivia)
 {
     return trivia.IsMultiLineComment() || trivia.IsMultiLineDocComment();
 }
예제 #5
0
 protected override bool IsMultilineComment(SyntaxTrivia trivia)
 {
     return(trivia.IsMultiLineComment() || trivia.IsMultiLineDocComment());
 }
예제 #6
0
 private static bool IsMultilineComment(SyntaxTrivia trivia1)
 {
     return(trivia1.IsMultiLineComment() || trivia1.IsMultiLineDocComment());
 }
예제 #7
0
 private static bool IsMultilineComment(SyntaxTrivia trivia1)
 {
     return trivia1.IsMultiLineComment() || trivia1.IsMultiLineDocComment();
 }
 protected override bool IsMultilineComment(SyntaxTrivia trivia)
 => trivia.IsMultiLineComment() || trivia.IsMultiLineDocComment();