Skip to content

Commit 1e686c4

Browse files
committed
fix: keep generic method call leading comments on their own line
1 parent d3d6f6b commit 1e686c4

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/comments.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ function handleMemberChainComments(commentNode: CommentNode) {
193193
(enclosingNode?.type === SyntaxType.FieldAccess ||
194194
(enclosingNode?.type === SyntaxType.MethodInvocation &&
195195
precedingNode?.end.row !== commentNode.start.row)) &&
196-
followingNode?.type === SyntaxType.Identifier
196+
(followingNode?.type === SyntaxType.Identifier ||
197+
followingNode?.type === SyntaxType.TypeArguments)
197198
) {
198199
util.addLeadingComment(enclosingNode, commentNode);
199200
return true;

test/unit-test/member_chain/_input.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ public void doSomethingWithComment() {
112112
.something().more();
113113
}
114114

115+
public void genericMethodWithLeadingComment() {
116+
a
117+
// 1
118+
.b()
119+
// 2
120+
.<C>c();
121+
}
122+
115123
public void doSomethingLongNew() {
116124
return something().more().and().that().as().well().but().not().something().something();
117125
}

test/unit-test/member_chain/_output.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ public void doSomethingWithComment() {
119119
.more();
120120
}
121121

122+
public void genericMethodWithLeadingComment() {
123+
a
124+
// 1
125+
.b()
126+
// 2
127+
.<C>c();
128+
}
129+
122130
public void doSomethingLongNew() {
123131
return something()
124132
.more()

0 commit comments

Comments
 (0)