From: Sergey Matveev Date: Wed, 18 Dec 2019 15:49:05 +0000 (+0300) Subject: Draft gogetdoc Vim plugin with popups X-Git-Url: http://www.git.stargrave.org/?p=dotfiles.git;a=commitdiff_plain;h=efa0572a0e97ddebb160f21d27885679048f832f Draft gogetdoc Vim plugin with popups --- diff --git a/vim/.vim/ftplugin/go/gogetdoc.vim b/vim/.vim/ftplugin/go/gogetdoc.vim new file mode 100644 index 0000000..199b39f --- /dev/null +++ b/vim/.vim/ftplugin/go/gogetdoc.vim @@ -0,0 +1,34 @@ +" Popup documentation of specified object under the cursor +" Requires github.com/zmb3/gogetdoc in the $PATH + +function! LintStatus() + if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif + return "" +endfunction + +function! GoGetDocGot(ch) + let msgs = [] + while ch_status(a:ch) == "buffered" + let msgs = add(msgs, ch_read(a:ch)) + endwhile + if exists("b:godocid") | call popup_close(b:godocid) | endif + if len(msgs) == 0 + echohl WarningMsg | echomsg "No go doc" | echohl None + return + endif + let msgs = msgs[2:] + let b:godocid = popup_atcursor(msgs[2:], {"wrap": 0, "title": msgs[0], "move": "word"}) +endfunction + +function! s:GoGetDoc() + if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return | endif + let pos = line2byte(line(".")) + col(".") - 1 + let cmdline = "gogetdoc -pos " . expand("%p") . ":#" . pos + let b:gogetdoc_job = job_start(cmdline, { + \"in_mode": "nl", + \"err_io": "null", + \"close_cb": "GoGetDocGot", + \}) +endfunction + +nmap :call GoGetDoc()