go-plus
go-plus copied to clipboard
Show documentation on autocomplete
Look at this example in a java editor, when the autocomplete open, it shows the related documentation to that attributem if available:

Is it possible to show the documentation of a method/variable/etc.., if it has, in go-plus?
@diegobernardes I would also love to see this feature in go-plus but I guess this is not a low hanging fruit since gocode does not offer such a feature. The JetBrains Go plugin supports the documentation on autocomplete (https://github.com/go-lang-plugin-org/go-lang-idea-plugin). Maybe one could get inspired how to do this efficiently.
gocode does not have, but we can do it with godoc:
godoc io/ioutil ReadFile
func ReadFile(filename string) ([]byte, error)
ReadFile reads the file named by filename and returns the contents. A
successful call returns err == nil, not err == EOF. Because ReadFile
reads the whole file, it does not treat an EOF from Read as an error to
be reported.
#12 this issue is to integrate godoc into the project, maybe the same integration can be used to do this.
@diegobernardes very nice suggestion. shouldn't be too hard to pipe the currently selected autocomplete function into godoc.
I second this, this feature is a must-have IMO. I imagine something slightly different, like vscode's calltip:

The calltip follows the cursor as you type and if you call another function (as a parameter to the first function) the tooltip updates with the documentation of the new function you're calling.
Maybe we can reuse go-tip's box to some extent?

Or perhaps extend the lint tooltips if possible:

Since this has been open since February, I'll try to implement something (might take a while because I'm not familiar with Atom internals).
My initial thought is to see how the 'statusbar function signature' works (how it gets the byte offset of where the cursor is right now and how it sends the unsaved file's buffer content to godoc's stdin) and use gogetdoc to fetch the documentation that will output something like
{"name":"Int","import":"flag","decl":"func Int(name string, value int, usage string) *int","doc":"Int defines an int flag with specified name, default value, and usage string.\nThe return value is the address of an int variable that stores the value of the flag.\n","pos":"/usr/local/go/src/flag/flag.go:609:6"}
then build (or use some enhanced tooltip support that Atom hopefully already has) a tooltip (or toggle the visibility of a previously built tooltip) that follows the typing cursor and fills it with decl and doc.
As an extra, since we'll get the function and package name from gogetdoc, we could show a godoc documentation on the side automatically (either by using godoc.org or using a local godoc -http server) like that:

With the option to update the godoc page automatically as you type or only if you hit ALT+D or something.
Thoughts?
Hey @dansouza - I also enjoy this feature in VS Code and think it would be a good addition. However I'm not sure it addresses the original issue here. This issue seems to be for getting documentation on the autocomplete suggestions, not for text that's already in the buffer.
The distinction here is that in the former case, you can see the doc for various identifiers before you elect to use them. In this case the doc may be helpful in determining which method to call.
Your proposal to mimic the behavior of VS Code shows the doc only after the user has decided to use the function, so a user that isn't sure which method to call won't really benefit.
So my thought is that we actually have two separate issues here:
- Show some form of documentation with autocomplete suggestions.
- Show documentation in a tooltip as the user is typing.
I totally agree with your proposal for 2 and would be happy to help you work on it, but I think we should create a separate issue and leave this issue for the first case. I did toy around with a "follow cursor" option in the original godoc package (see https://github.com/zmb3/godoc/pull/40).
I think we can address item 1 by adding some information to our Autocomplete Plus provider. Specifically, I think we could set description to the first line of the doc, and descriptionMoreURL to the godoc.org URL, similar to how vim-go's :GoDocBrowser command works.
@zmb3 I see your point - I'll create a separate issue and tag you - and I appreciate any help you can give with it since I'll have to learn about Atom internals and whatnot. Thanks!