You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The go/doc package has references to the components of the AST that it describes. For some historical reason, though, it sets the FuncBody part of the FuncDecl to nil, which makes it hard to recover the source code associated with a declaration.
It seems that godoc use to do this of the "src" flag was not set, which makes sense. But at some point the action was moved into go/doc itself, and not protected by a flag, which means the source is never available.
As part of the go.12 release, I'd like to make cmd/doc supersede godoc's command line features entirely (can't find the issue number at the moment) and add support for examples (#26715). Both of these are made much more awkward by this property of go/doc.
Finally, as a point of order, it's rude for a package to overwrite a data structure passed to it, especially if the property is not documented.
I'd like to delete the nil-ing out of these fields (the function body is not the only one), or at least provide a mechanism to prevent it.
The text was updated successfully, but these errors were encountered:
After talking with @gri, we will try to fix this by adding a new Mode bit called KeepSource or something like that, which will be off by default and therefore backwards-compatible.
It's long-desired but was blocked by #26835. That is now fixed, so
it's easy. When -src is off, we behave as before. But with -src
set, initialize the go/doc package to preserve the original AST and
things flow very easily.
With -src, since you're seeing inside the package source anyway it
shows unexported fields and constants: you see the original source.
But you still need -u to ask about them.
Fixes#18807
Change-Id: I473e90323b4eff0735360274dc0d2d9dba16ff8b
Reviewed-on: https://go-review.googlesource.com/c/140959
Reviewed-by: Andrew Gerrand <[email protected]>
Run-TryBot: Andrew Gerrand <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
The go/doc package has references to the components of the AST that it describes. For some historical reason, though, it sets the FuncBody part of the FuncDecl to nil, which makes it hard to recover the source code associated with a declaration.
It seems that godoc use to do this of the "src" flag was not set, which makes sense. But at some point the action was moved into go/doc itself, and not protected by a flag, which means the source is never available.
As part of the go.12 release, I'd like to make cmd/doc supersede godoc's command line features entirely (can't find the issue number at the moment) and add support for examples (#26715). Both of these are made much more awkward by this property of go/doc.
Finally, as a point of order, it's rude for a package to overwrite a data structure passed to it, especially if the property is not documented.
I'd like to delete the nil-ing out of these fields (the function body is not the only one), or at least provide a mechanism to prevent it.
The text was updated successfully, but these errors were encountered: