From efa0572a0e97ddebb160f21d27885679048f832f Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 18 Dec 2019 18:49:05 +0300 Subject: [PATCH] Draft gogetdoc Vim plugin with popups --- vim/.vim/ftplugin/go/gogetdoc.vim | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 vim/.vim/ftplugin/go/gogetdoc.vim 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() -- 2.44.0