]> Sergey Matveev's repositories - dotfiles.git/blobdiff - vim/.vim/autoload/go/getdoc.vim
Vim scripts refactoring
[dotfiles.git] / vim / .vim / autoload / go / getdoc.vim
diff --git a/vim/.vim/autoload/go/getdoc.vim b/vim/.vim/autoload/go/getdoc.vim
new file mode 100644 (file)
index 0000000..922c9cd
--- /dev/null
@@ -0,0 +1,34 @@
+" Popup documentation of specified object under the cursor
+" Requires github.com/zmb3/gogetdoc in the $PATH
+
+function! go#getdoc#status()
+    if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif
+    return ""
+endfunction
+
+function! go#getdoc#got(ch) abort
+    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:-2],
+        \ {"wrap": 0, "title": msgs[0], "move": "word"})
+endfunction
+
+function! go#getdoc#do() abort
+    if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return | endif
+    let pos = line2byte(line(".")) + col(".") - 2
+    let cmdline = "gogetdoc -pos " . expand("%p") . ":#" . pos
+    echomsg cmdline
+    let b:gogetdoc_job = job_start(cmdline, {
+        \"in_mode": "nl",
+        \"err_io": "null",
+        \"close_cb": "go#getdoc#got",
+    \})
+endfunction