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

How to get help of a method? #65

Open
dlintw opened this issue Jul 23, 2019 · 5 comments
Open

How to get help of a method? #65

dlintw opened this issue Jul 23, 2019 · 5 comments

Comments

@dlintw
Copy link

dlintw commented Jul 23, 2019

for example, show call shell of "go doc fmt.Println" to show document


import "fmt"
fmt.Println?
@cosmos72
Copy link
Owner

There is no mechanism at the moment to retrieve and print the documentation of a function, type, method, variable or constant.

It would definitely be useful. Do you know about an API (except launching another process, as go doc is) to retrieve such documentation?

Currently, evaluating fmt.Println will show the function value and its signature (i.e. its type), but not its documentation:

gomacro> import "fmt"
gomacro> fmt.Println
0x1993260       // func(...interface{}) (int, error)

@cosmos72
Copy link
Owner

Stackoverflow has an answer, and it's not really encouraging:
https://stackoverflow.com/questions/54558527/how-to-get-func-documentation-in-golang
There is no straightforward API - one needs to locate and parse the relevant source code in order to retrieve (all) its comments

@dlintw
Copy link
Author

dlintw commented Jul 24, 2019

Does this helpful? https://github.com/fatih/vim-go-tutorial#documentation-lookup
In vim, we can use :GoDoc to get the document
I guess the easier implementation is just call the shell to execute "go doc fmt.Println"

@cosmos72
Copy link
Owner

I agree, the quickest solution is to execute go doc fmt.Println. I will probably implement this.

The alternative is to find the sources, parse them, pass them to go/doc.New(), and finally retrieve the documentation from the created doc.Package

@glycerine
Copy link
Contributor

the new gopls (https://github.com/golang/tools/tree/master/gopls) lets you jump to code definitions, quickly. And typically the docs are just above the function, so that could work nicely. It is obviously written in Go, but I'm not sure about the library API. Might be usable from Go. It does seem that most of the package surface (https://github.com/golang/tools/tree/master/gopls) is internal. But since it is supposed to be a long running server process, it might be fine to start it once on demand and then query/update.

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

No branches or pull requests

3 participants