The packages go/types and go/doc are very powerful… But they seem to be completely unconnected?
In my case, I need to get detailed type information for a package (which is easy to accomplish using go/importer with go/types) but I want to have the documentation with them (which is not included in go/types, only go/doc or go/ast).
Is there any way to have types and documentation together?
An example:
How to get the go/type and the documentation for “fmt.Printf”?
Maybe I miss the point of your question, but package documentation is not included in separate documentation files but rather generated through the godoc tool from the code itself and from comments placed accordingly (e.g., above “package main” or above a function, type, or method, etc.). Is this what you are looking for?
type InfoIWantToGet struct {
Type types.Type // from go/types
Doc string // from go/doc
}
func getInfo(symbol string) InfoIWantToGet {
// how? :D
}
// use: getInfo("fmt.Printf")
Like I said: I need to get the type and documentation for golang symbols.
For information on the type, I would use the package go/types with go/importer.
And for the documentation I would use go/doc with the parsed ast.
But this seems like parsing all packages twice…
Is parsing twice really so bad? Unless your code runs in a super time critical scenario, worrying about performance should not be your first and foremost concern. Make the code work now and optimize later (if needed at all).