How to get help of a method?
for example, show call shell of "go doc fmt.Println" to show document
import "fmt"
fmt.Println?
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)
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
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"
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
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.