]> Sergey Matveev's repositories - dotfiles.git/blob - vim/.vim/autoload/go/getdoc.vim
Vim scripts refactoring
[dotfiles.git] / vim / .vim / autoload / go / getdoc.vim
1 " Popup documentation of specified object under the cursor
2 " Requires github.com/zmb3/gogetdoc in the $PATH
3
4 function! go#getdoc#status()
5     if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif
6     return ""
7 endfunction
8
9 function! go#getdoc#got(ch) abort
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:-2],
21         \ {"wrap": 0, "title": msgs[0], "move": "word"})
22 endfunction
23
24 function! go#getdoc#do() abort
25     if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return | endif
26     let pos = line2byte(line(".")) + col(".") - 2
27     let cmdline = "gogetdoc -pos " . expand("%p") . ":#" . pos
28     echomsg cmdline
29     let b:gogetdoc_job = job_start(cmdline, {
30         \"in_mode": "nl",
31         \"err_io": "null",
32         \"close_cb": "go#getdoc#got",
33     \})
34 endfunction