Vim-go: Preview buffer does not show Comments

Created on 7 Mar 2016  路  8Comments  路  Source: fatih/vim-go

Expected behavior

Upon selecting an item from C-x C-o omnicomplete's menu, the Preview window/buffer:

1) should open, showing the function signature (check, it does this)
2) should show the Documentation from // FuncName does this and that of the comment, usually UNDER the function name (that's how other languages do it in vim).

Here's a screenshot I found of python:

Preview buffer showing comments

Actual behavior

It opens the Preview buffer/window, shows the function signature; but, it does not show any documentation/comments. See screenshot below when trying to use fmt.Prin:

screen shot 2016-03-08 at 10 14 46 am

Note that :GoDoc works when hovering on the Printf() so documentation is being found.

Steps to reproduce:

  1. ensure you have set completeopt+=preview at least set in .vimrc (must be set before starting vim)
  2. create a new main.go file
  3. import fmt
  4. type some source code for fmt.
  5. press ctrl-x ctrl-o

As you cycle through the menu options, the Preview buffer should open showing the signatures.

But, no comments are shown. Nor are

Configuration

vimrc you used to reproduce:

execute pathogen#infect()
syntax enable 
filetype plugin indent on

map <C-J> :bprev<CR>
map <C-K> :bnext<CR>

set hidden
set wrap
set linebreak
set formatoptions-=t
set tabstop=4
set shiftwidth=4
set directory^=~/.vim/swp//
set number
set noshowmode

" overriding sensible settings
let g:netrw_liststyle=3

" IDE-like intellisense
set completeopt=longest,menuone,preview
"inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
"inoremap <expr> <C-n> pumvisible() ? '<C-n>' : 
"           \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
"inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
"           \ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'

" SuperTab
"let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
"let g:SuperTabDefaultCompletionType = "context"

" neocomplete
"let g:neocomplete#enable_at_startup = 1
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#enable_smart_case = 1
"let g:neocomplete#sources#syntax#min_keyword_length = 3 
"let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'

" Plugin key-mappings.
"inoremap <expr><C-g>     neocomplete#undo_completion()
"inoremap <expr><C-l>     neocomplete#complete_common_string()

" DISABLED
" <CR>: close popup and save indent.
"inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
"function! s:my_cr_function()
"  return neocomplete#close_popup() . "\<CR>"
"endfunction
" <TAB>: completion.


"inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
"inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
"inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
"inoremap <expr><C-y>  neocomplete#close_popup()
"inoremap <expr><C-e>  neocomplete#cancel_popup()

"let g:neocomplete#data_directory = '~/.vim/tmp/neocomplete'
"let g:neocomplete#sources#tags#cache_limit_size = 16777216 " 16MB

" fuzzy completion breaks dot-repeat more noticeably
" https://github.com/Shougo/neocomplete.vim/issues/332
"let g:neocomplete#enable_fuzzy_completion = 0

" always use completions from all buffers
"if !exists('g:neocomplete#same_filetypes')
"  let g:neocomplete#same_filetypes = {}
"endif
"let g:neocomplete#same_filetypes._ = '_'

" Go related mappings
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <Leader>gd <Plug>(go-doc)
au FileType go nmap <Leader>r <Plug>(go-run)
au FileType go nmap <Leader>b <Plug>(go-build)
au FileType go nmap <Leader>t <Plug>(go-test)
au FileType go nmap gd <Plug>(go-def-tab)

" plugin: syntastic
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 0 " use :lopen / :lclose to open/show
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
"let g:airline#extensions#tabline#left_sep = ' '
"let g:airline#extensions#tabline#left_alt_sep = '|'
"let g:airline_powerline_fonts = 1  " use when font isn't patched
if !exists('g:airline_symbols')
  let g:airline_symbols = {} " fixes fontconfig versions 
endif
let g:airline_symbols.space = "\ua0"
let timeoutlen = 50

" let g:go_disable_autoinstall = 0

" Highlight
let g:go_highlight_functions = 1  
let g:go_highlight_methods = 1  
let g:go_highlight_structs = 1  
let g:go_highlight_interfaces = 1
let g:go_highlight_operators = 1  
let g:go_highlight_build_constraints = 1

" fixing 256 colors in tmux
"set term=xterm-256color
set t_Co=256                        " force vim to use 256 colors

" fixing Background Color Erase when term is set to non-xterm
if &term =~ '256color'
  " disable Background Color Erase (BCE) so that color schemes
  " render properly when inside 256-color tmux and GNU screen.
  " see also http://snk.tuxfamily.org/log/vim-256color-bce.html
  set t_ut=
else
  " switch to fallback mode when there xterm-256color isn't detected
  " (e.g. gnome's Drop Down Shell extension)
"  let g:solarized_termcolors=256
endif

" solarized theme
set background=dark
colorscheme solarized


vim version:

$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Feb 18 2016 14:44:04)
MacOS X (unix) version
Included patches: 1-1345
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +tag_binary
+arabic          +file_in_path    +mouse_sgr       +tag_old_static
+autocmd         +find_in_path    -mouse_sysmouse  -tag_any_white
-balloon_eval    +float           +mouse_urxvt     -tcl
-browse          +folding         +mouse_xterm     +terminfo
++builtin_terms  -footer          +multi_byte      +termresponse
+byte_offset     +fork()          +multi_lang      +textobjects
+channel         -gettext         -mzscheme        +title
+cindent         -hangul_input    +netbeans_intg   -toolbar
-clientserver    +iconv           +path_extra      +user_commands
+clipboard       +insert_expand   +perl            +vertsplit
+cmdline_compl   +job             +persistent_undo +virtualedit
+cmdline_hist    +jumplist        +postscript      +visual
+cmdline_info    +keymap          +printer         +visualextra
+comments        +langmap         +profile         +viminfo
+conceal         +libcall         +python          +vreplace
+cryptv          +linebreak       -python3         +wildignore
+cscope          +lispindent      +quickfix        +wildmenu
+cursorbind      +listcmds        +reltime         +windows
+cursorshape     +localmap        +rightleft       +writebackup
+dialog_con      +lua             +ruby            -X11
+diff            +menu            +scrollbind      -xfontset
+digraphs        +mksession       +signs           -xim
-dnd             +modify_fname    +smartindent     -xsmp
-ebcdic          +mouse           -sniff           -xterm_clipboard
+emacs_tags      -mouseshape      +startuptime     -xterm_save
+eval            +mouse_dec       +statusline      -xpm
+ex_extra        -mouse_gpm       -sun_workshop
+extra_search    -mouse_jsbterm   +syntax
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H   -F/usr/local/Frameworks -DMACOS_X_UNIX  -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: /usr/bin/clang   -L. -L/usr/local/lib -L/usr/local/lib -F/usr/local/Frameworks -Wl,-headerpad_max_install_names -o vim        -lm  -lncurses -liconv -framework Cocoa  -L/usr/local/lib -llua -fstack-protector  -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -F/usr/local/Cellar/python/2.7.11/Frameworks -framework Python   -lruby.2.0.0 -lobjc

vim-go version:

commit fd5661a1e16a1fd41385d7011877bfa1f0a1353f
Merge: 5f64a57 65ef9bc
Author: Fatih Arslan <[email protected]>
Date:   Thu Mar 3 09:37:40 2016 +0200

    Merge pull request #748 from bhcleek/master

    show output of :GoRun

go version:

$ go version
go version go1.6 darwin/amd64

Most helpful comment

Is there any update on this topic? I am really missing that feature :)

All 8 comments

Thanks @eduncan911 for the report. I'll look into it soon, I don't have much time nowadays.

If you can take 5 minutes and point me to where it is in code, I'll try my luck at a PR. :+1:

  • Would I need to lookup the func in GoDoc? Or, do you think it is ctags related (e.g. ctags not finding the comments)?
  • What file(s) can you think of to look in for 1) finding the comments and 2) what to modify?

I know 0 about vimscript. So any help u can give would help!

I think it's not possible @eduncan911. The information is passed via gocode and we print the result. The code is in complete.vim. Of course I didn't looked into that much, but just wanted to give heads up until I have more information.

Hey @fatih ! You're right. I dug into gocode by @nsf and saw where it does not do comments.

So, this particular issue could possibly be closed... Except...

I saw @nsf's call to arms to rewrite the codebase because is, in his own words, horrible and is a miracle that it actually works (it was written for pre Go 1.0 code, using ast - precompiled analysis where we should now be doing code analysis.

One of things he mentions is Documentation/Comments being exposed.

But the interesting attribute in that discussion thread is that the Goclipse IDE uses a "funny situation" of where it uses gocode for Code Completion; but, then it uses oracle for documentation of that code completion.

Perhaps a similar thing can happen here with vim-go: use gocode for code completion, and lookup the docs with oracle.

I tried this tonight; but, i can't seem to extract any documentation. There must be a flag I am unaware of.

I'll keep trying.

I don't think oracle does doc comments.

I found out that Go 1.5 has a new feature of go doc:

$ go doc github.com/eduncan911/go-mspec AssertionsFn
func AssertionsFn(fn func(s *Specification) Assert)
    AssertionsFn will assign the assertions used for all tests. The specified
    struct must implement the mspec.Assert interface.

       mspec.AssertionsFn(func(s *Specification) Assert {
            return &MyCustomAssertions{}
       })


This is EXACTLY what we are after!!! :+1: What you see is my documentation as well as the inline example I have in the comment.

Another one from the stdlib:

$ go doc os Create
func Create(name string) (*File, error)
    Create creates the named file with mode 0666 (before umask), truncating it
    if it already exists. If successful, methods on the returned File can be
    used for I/O; the associated file descriptor has mode O_RDWR. If there is an
    error, it will be of type *PathError.

The standard library lookups are short it seems (the os above for the os package).

It requires the "package" name, not the file path, and the func name. I think these can be parsed out from the omnicomplete menu. It seems you know the context that is being completed (so that should get the package); and, we have the func name. The regex will have to be compatible with all other types as well though (type, const, var definitions, etc).

Also, it seems this is what :GoDoc should be using now since 1.5 as well, since it only shows that one method.

So perhaps changing the way :GoDoc works, and then calling it with the Omnicomplete stuff is the resolution here.

For giggles, I dumped the output of gocode from the complete.vim:

gocode -in=/var/folders/fk/kyjxtwcj7ync9w2y2l6573kh0000gn/T/vpd6MSG/14 -f=vim autocomplete /Users/eric/go/src/github.com/eduncan911/go-mspec/bdd.go 487

Basically, I am not sure how the Preview window is opening though through the omnicomplete stuff. because there has to be additional parameters for the omnicomplete menu: one for the menu/popup, and one for additional info for like the Documentation to display that other languages fill out.

Perhaps the (hack?) fix is to leave it using gocode, and for each "omnicomplete -> ctrl-n/next", run go doc <package name> <func> and populate the Preview buffer.

I just don't know where that is being set.

@eduncan911 it is being set here https://github.com/fatih/vim-go/blob/master/autoload/go/complete.vim#L102

Read :h complete-items

The problem with go doc and others are, they are not identifier based. For example suppose you have something like x.Foo(). What is x here? Is it package name? Is it local variable? Is it a receiver? Gocode traverses the AST and returns the correct candidate for it. But as you also said, it's current architecture needs a rewrite as it doesn't provide that functionality.

Until gocode has written it there is not much I can do.

However I'll start working on Guru implementation, and Alan has worked on a new completion engine, which I'm going to check and try to ingrate if it's makes sense.

Feel free to reopen this, but as I said the underlying problem is something we can't tackle until it has changed with something completely new. Thanks!

Is there any update on this topic? I am really missing that feature :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhangjing picture zhangjing  路  3Comments

SirmaXX picture SirmaXX  路  3Comments

smontazeran picture smontazeran  路  4Comments

cassiobotaro picture cassiobotaro  路  3Comments

andrejvanderzee picture andrejvanderzee  路  3Comments