Skip to content

Commit 8fe9b27

Browse files
committed
fix(codegen): we should use the right context now for the comment
1 parent 43f68ed commit 8fe9b27

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser

code-generation/protocol-base-mspec/src/main/java/org/apache/plc4x/plugins/codegenerator/language/mspec/parser/MessageFormatListener.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ public void enterFile(MSpecParser.FileContext ctx) {
9696

9797
// Helper: Attach comment if directly above or on the same line
9898
private String consumePendingComment(ParserRuleContext ctx) {
99-
ctx = ctx.getParent(); // TODO: this is because of the stupid bracket which is considered a previous token... figure out a smart way
10099
Token startToken = ctx.getStart();
100+
while (startToken.getType() != MSpecLexer.LBRACKET) { // Bit hacky workaround to assume start is always the bracket but should work
101+
ctx = ctx.getParent(); // Switch to parent context...
102+
startToken = ctx.getStart(); // ...and use this as start
103+
}
101104

102105
List<Token> frontComments = new LinkedList<>();
103106
int tokenIndex = startToken.getTokenIndex();

0 commit comments

Comments
 (0)