kotlinx / ast

Generic AST parsing library for kotlin multiplatform
Apache License 2.0
316 stars 22 forks source link

End-of-line comments not available in summary #67

Open henrikbarium opened 2 years ago

henrikbarium commented 2 years ago

If I run:

KotlinGrammarAntlrKotlinParser.parseKotlinFile(AstSource.String("source", "//line comment"))

The resulting raw AST contains the line comment (as expected). If I call summary() on that AST, the line comment is represented as a KlassComment (again, as expected).

Then, if I run:

KotlinGrammarAntlrKotlinParser.parseKotlinFile(AstSource.String("source", "val answer = 42 //line comment"))

Again, the resulting raw AST contains the line comment (as expected). However, if I call summary() on that AST I cannot find the comment anywhere.

Am I missing something or is this a limitation/bug in the library?

drieks commented 2 years ago

Hi @henrikbarium, thank you for reporting, I will fix it.

drieks commented 2 years ago

Hi @henrikbarium, should be working now. Some AST-Nodes were dropping "unrelated" AST-Nodes, but comments were handled as unrelated. I changed this "related" filter and added a new comment filter to keep all comment nodes.

Please try version 7a60784a13.