Skip to content

Commit

Permalink
indent comments on close bracket. (#1062)
Browse files Browse the repository at this point in the history
closes #1059
  • Loading branch information
belav authored Dec 10, 2023
1 parent 935e36c commit d9b0a88
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ CallMethod(
]
);

CallMethod(
[
// some comment
]
);

CallMethod(
[
1,
// some comment
// and more
]
);

class MyClass
{
private readonly List<string> _items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ or EqualsValueClauseSyntax
? Doc.HardLine
: Doc.IfBreak(Doc.Line, Doc.Null)
: Doc.Null,
Token.Print(node.CloseBracketToken, context)
node.CloseBracketToken.LeadingTrivia.Any(o => o.IsComment())
? Doc.Concat(
Doc.Indent(Token.PrintLeadingTrivia(node.CloseBracketToken, context)),
Doc.HardLine
)
: Doc.Null,
Token.PrintWithoutLeadingTrivia(node.CloseBracketToken, context)
);
return Doc.Group(result);
}
Expand Down
5 changes: 4 additions & 1 deletion Src/CSharpier/SyntaxPrinter/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ is InterpolatedStringExpressionSyntax

public static Doc PrintLeadingTrivia(SyntaxToken syntaxToken, FormattingContext context)
{
var isClosingBrace = syntaxToken.RawSyntaxKind() == SyntaxKind.CloseBraceToken;
var isClosingBrace =
syntaxToken.RawSyntaxKind() == SyntaxKind.CloseBraceToken
|| syntaxToken.Parent is CollectionExpressionSyntax
&& syntaxToken.RawSyntaxKind() == SyntaxKind.CloseBracketToken;

var printedTrivia = PrivatePrintLeadingTrivia(
syntaxToken.LeadingTrivia,
Expand Down

0 comments on commit d9b0a88

Please sign in to comment.