-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
go/printer: CommentedNode behavior is partially undocumented #39219
Comments
Change https://golang.org/cl/240217 mentions this issue: |
Change https://golang.org/cl/276632 mentions this issue: |
Using a All this is in service of modifying the doc to shorten long literals, replacing them with comments. If there were a way to do that by adding comment nodes directly to the AST, then that might be simpler. |
…ering The presence of a long literal caused all struct fields comments to be removed. This imperfectly fixes the problem by collecting all comments when walking the declaration AST. Previously, it was thought that the comments in an ast.CommentedNode would augment the existing comments instead of replacing them (see golang/go#39219). The fix, as in https://golang.org/cl/240217 and copied here, is to collect all comments during the walk. This isn't sufficient, because using a CommentedNode also turns off the "contains filtered or unexported" comments that are normally added during printing. So we have to add them back manually, which is tricky, and can't be done perfectly (there are extra blank lines). For golang/go#42425 Change-Id: I0bd8e5ddfc764bc3c7610575e1e3eedf9c0bfd84 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/276632 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
Change https://golang.org/cl/284235 mentions this issue: |
Using an ast.CommentedNode add comments for long literals does not work well (golang/go#42425, golang/go#39219). Instead, modify the AST in place, adding comments directly to the existing nodes. Protect this change under an experiment until we have more confidence that it doesn't make things worse. Fixes golang/go#42425 Change-Id: I7e92356beb7fb873271bb9dd5ee37773d750aeb6 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/284235 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
What did you do?
I read the documentation of package
go/printer
in order to understand how to useprinter.CommentedNode
.CommentedNode
is currently defined as:It is also mentioned in the documentation of the
Config.Fprint
method:As well as the
format.Node
function, but there isn't additional information there.What did you expect to see?
Documentation that would allow me to learn an answer to the question of "what happens to comments that are already a part of the
Node
being wrapped in aprinter.CommentedNode
?" without having to also read the source code.What did you see instead?
Insufficient documentation to know what the intended behavior is.
/cc @griesemer @josharian
The text was updated successfully, but these errors were encountered: