maralla / completor.vim

Async completion framework made ease.
MIT License
1.29k stars 63 forks source link

Add support for Go docs #202

Closed leighmcculloch closed 6 years ago

leighmcculloch commented 6 years ago

What

Add support for retrieving the Go doc using the godoc command and displaying that in the docs preview window.

Why

So that the docs for an identifier, function or struct can be viewed within VIM when scrolling through the list of possible autocomplete results. As discussed in #199.

Note

  1. The csv-with-package gocode format includes the package name as the last (fourth) column in the csv. The package name is required when doing the godoc lookup.
  2. This works but I don't think this is in a state where it can be merged. The format_cmd function only lets me return a single command, and so I've hacked the godoc call into parse, but that means parse is given a list of 100 possible autocompletions, it's calling godoc 100 times. I'd like to do the godoc call only when an option is selected and the doc is actually being displayed, but I can't see how to do that.
maralla commented 6 years ago

Thanks for your contribution! Completor uses gocode to drive the auto completion for golang and gocode itself does not support extraction docs of the completion items. Right now I don't think it has any easy and efficient way to gather docs of completion items. Using subprocess is unacceptable. The pr #206 provide a workaround and intuitive way to view the docs of an item. Please check it out.

After updating to the latest commit to view the doc you can use the function call completor#do('doc') with the following key mapping (You must have gogetdoc installed):

" view doc
noremap <silent> <leader>c :call completor#do('doc')<CR>
" go to definition
noremap <silent> <leader>d :call completor#do('definition')<CR>
leighmcculloch commented 6 years ago

@maralla Ah that's cool. I would have thought adding that functionality to this vim plugin in that way, as a new feature triggered with a key sequence instead of as part of completion, was outside the scope of this project. Especially given that vim-go provides this functionality already with the :GoDoc function.

Thanks for trying to find a way to make it accessible. I'll probably stick to using the vim-go option as that what I've already been using.

❤️