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
cmd/doc: inconsistent removal of directive comments #56592
Comments
cmd/doc/pkg.go :: |
cc @robpike |
This is surely an issue with the go/doc package, not the cmd/doc command, which just formats what the package provides. |
Hi all, this popped up again - is there any way I can help get traction on it? |
Change https://go.dev/cl/483055 mentions this issue: |
Thanks! I tried it at gotip and I see something unexpected: given this file:
go doc shows:
Note the directive is still present. gotip says:
The directive is gone (yay) but there's now a blank like. Is that expected? @ianlancetaylor |
@thockin It turns out to be rather painful to avoid. Or to put it more fairly, I was sufficiently exhausted by the effort tracking through all the code that I didn't feel like trying to fix that too. It's because go/ast records positions for all comments and tokens, and go/format honors those positions to try to recreate the same format as the original file. That means that without extra work, when a comment line disappears, go/format inserts an extra line to get back to the expected position. Just disregarding the positions doesn't work, as that would mean that we lose track of which comments come before a field and which comments appear on the same line as a field. So removing the blank line is non-trivial, or, at least, I haven't seen a simple solution. I do think that the gotip output is better. But as you say it's perhaps not ideal. By all means open a new issue. |
ACK! Thanks. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Given this file:
Run
go doc
.Note the "magic" directive is present.
Still has magic directive.
This time, the magic is detected as a directive and removed. Shouldn't that happen in all cases?
What did you expect to see?
Consistent stripping of "directives".
What did you see instead?
Inconsistent stripping of "directives".
The text was updated successfully, but these errors were encountered: