]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Draft gogetdoc Vim plugin with popups
authorSergey Matveev <stargrave@stargrave.org>
Wed, 18 Dec 2019 15:49:05 +0000 (18:49 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 18 Dec 2019 15:49:05 +0000 (18:49 +0300)
vim/.vim/ftplugin/go/gogetdoc.vim [new file with mode: 0644]

diff --git a/vim/.vim/ftplugin/go/gogetdoc.vim b/vim/.vim/ftplugin/go/gogetdoc.vim
new file mode 100644 (file)
index 0000000..199b39f
--- /dev/null
@@ -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 <buffer> <silent> <CR> :call <SID>GoGetDoc()<CR>