]> Sergey Matveev's repositories - dotfiles.git/blob - vim/.vim/ftplugin/go/gogetdoc.vim
Draft gogetdoc Vim plugin with popups
[dotfiles.git] / vim / .vim / ftplugin / go / gogetdoc.vim
1 " Popup documentation of specified object under the cursor
2 " Requires github.com/zmb3/gogetdoc in the $PATH
3
4 function! LintStatus()
5     if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif
6     return ""
7 endfunction
8
9 function! GoGetDocGot(ch)
10     let msgs = []
11     while ch_status(a:ch) == "buffered"
12         let msgs = add(msgs, ch_read(a:ch))
13     endwhile
14     if exists("b:godocid") | call popup_close(b:godocid) | endif
15     if len(msgs) == 0
16         echohl WarningMsg | echomsg "No go doc" | echohl None
17         return
18     endif
19     let msgs = msgs[2:]
20     let b:godocid = popup_atcursor(msgs[2:], {"wrap": 0, "title": msgs[0], "move": "word"})
21 endfunction
22
23 function! s:GoGetDoc()
24     if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return | endif
25     let pos = line2byte(line(".")) + col(".") - 1
26     let cmdline = "gogetdoc -pos " . expand("%p") . ":#" . pos
27     let b:gogetdoc_job = job_start(cmdline, {
28         \"in_mode": "nl",
29         \"err_io": "null",
30         \"close_cb": "GoGetDocGot",
31     \})
32 endfunction
33
34 nmap <buffer> <silent> <CR> :call <SID>GoGetDoc()<CR>