Skip to content
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: show types for constants and variables that have initializers #33134

Open
bcmills opened this issue Jul 16, 2019 · 4 comments
Open

cmd/doc: show types for constants and variables that have initializers #33134

bcmills opened this issue Jul 16, 2019 · 4 comments

Comments

@bcmills
Copy link
Member

@bcmills bcmills commented Jul 16, 2019

Currently, if you ask go doc for an exported identifier, and it happens to be declared as a var or const with the type inferred from the initializer, the type of the variable does not appear in the output.

It is doubly frustrating if the initializer happens to refer to unexported identifiers, since go doc requires an extra flag before it will document those (#33133).

What version of Go are you using (go version)?

~/go/src$ go version
go version devel +87bf0b5c51 Tue Jul 16 13:17:46 2019 -0400 linux/amd64

What did you do?

~/go/src$ go doc go/build.ToolDir

What did you expect to see?

The documentation for and type of the go/build.ToolDir variable.

What did you see instead?

~/go/src$ go doc go/build.ToolDir
package build // import "go/build"

var ToolDir = getToolDir()
    ToolDir is the directory containing build tools.

No indication of whether ToolDir is a string, a []byte, or something else entirely. It isn't mentioned in the doc comment, and it shouldn't need to be mentioned in the doc comment because the compiler already knows what it is.

@bcmills
Copy link
Member Author

@bcmills bcmills commented Jul 16, 2019

@mvdan
Copy link
Member

@mvdan mvdan commented Jul 26, 2019

As far as I know, go doc doesn't do any typechecking - how would this work?

@robpike
Copy link
Contributor

@robpike robpike commented Jul 26, 2019

The go doc command shows you source code, it doesn't make up text. Adding the type would mean making something up that isn't explicitly there. While I understand what you're after, I'm not sure that's where we want to go.

@bcmills
Copy link
Member Author

@bcmills bcmills commented Jul 29, 2019

@ianthehat @stamblerre, is gopls a better fit for this?

(Will it be possible to query gopls for type information as succinctly as one can query go doc for literal documentation?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.