-
Notifications
You must be signed in to change notification settings - Fork 59
Comments in empty function/loop/if-statement bodies not found #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'll take a look at this now... |
Yeah if there's no decoration point after the comment, it'll attach it to the previous attachment point, which in the "empty function" example is |
Same with the for statement, in |
Take a look at positions.go in the gendst package... it shows exactly where each decoration point in on each node type. Might help track things down in future... ... |
e.g.: // BlockStmt(0)
if true /*Start*/ { /*Lbrace*/
i++
} /*End*/
// BlockStmt(1)
func() /*Start*/ { /*Lbrace*/ i++ } /*End*/ () |
The algorithm that associates comments with decoration attachment points is one of those things that doesn't have a well defined correct answer... so sometimes you get situations like this where it's not exactly straightforward. |
Alright, thanks for the clarification! This helps a lot :) One last thing: Does |
Hmm ... just been looking at this and it's not easy in a generalised way. Let me take another look... |
Yeah you'd probably want something like this: https://play.golang.org/p/NhLPbXeTCGo ... that |
Perfect! Thanks a lot for the help :) |
Hey @ec-m, I've just released v0.25.5 which makes that helper function public in the dstutil package. See documentation here. |
Awesome! Thanks 👍 |
Comments that are placed inside empty function, loop or if statement bodies are not found in the respective node's decorations. I would expect them to be placed somewhere in the e.g.
dst.FuncDeclDecorations
of the function or similarly thedst.ForStmtDecorations
of the loop declaration. This snipped demonstrates the issue:And here you can find code to reproduce the issue: https://play.golang.org/p/Yg9OOkoP6IF [Disclaimer: sometimes the playground needs multiple tries to import all packages, so if you encounter a
timeout running go build
error, just execute the code again.]I tried using
dst
in order to fix the issue golang/go#39753 I had withgo/ast
. As I am a fairly new user of this module, I might also have overlooked something - Please let me know if this is the case and how I could get the correct comment associations :) Thanks!go env
OutputThe text was updated successfully, but these errors were encountered: