From 9fe1a2a9a4894ab3bca418c4458c7c2fa323bb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=96R=C3=96SK=C5=90I=20Andr=C3=A1s?= Date: Wed, 16 Sep 2020 21:58:22 +0200 Subject: [PATCH] gopls: fixes based on krobelus@ review --- rc/tools/go/gopls.kak | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/rc/tools/go/gopls.kak b/rc/tools/go/gopls.kak index 1280a64f..6ae19e12 100644 --- a/rc/tools/go/gopls.kak +++ b/rc/tools/go/gopls.kak @@ -1,7 +1,7 @@ # gopls.kak: gopls bindings for kakoune define-command -params 1 -docstring %{ -gopls : gopls command wrapper for kakoune +gopls : gopls command wrapper All commands are forwarded to gopls utility Available commands are: @@ -41,7 +41,7 @@ evaluate-commands %sh{ fi } -# Temp dir prepatation +# Temp dir preparation declare-option -hidden str gopls_tmp_dir define-command -hidden -params 0 gopls-prepare %{ evaluate-commands %sh{ @@ -55,7 +55,7 @@ define-command -hidden -params 1 gopls-cmd %{ gopls-prepare evaluate-commands %sh{ dir=${kak_opt_gopls_tmp_dir} - eval "gopls $1 -w ${kak_buffile} 2> '${dir}/stderr'" + gopls $1 -w ${kak_buffile} 2> "${dir}/stderr" if [ $? -ne 0 ]; then # show error messages in *debug* buffer printf %s\\n "echo -debug %file{ '${dir}/stderr' }" @@ -67,17 +67,14 @@ define-command -hidden -params 1 gopls-cmd %{ # gopls definition define-command -hidden -params 0 gopls-def %{ - gopls-prepare evaluate-commands %sh{ - dir=${kak_opt_gopls_tmp_dir} - eval "gopls definition ${kak_buffile}:${kak_cursor_line}:${kak_cursor_column} \ - |sed -e 's/-.*//' -e 's/:/ /g' > '${dir}/jump'" - if [ -s "${dir}/jump" ]; then + jump=$( gopls definition ${kak_buffile}:${kak_cursor_line}:${kak_cursor_column} \ + |sed -e 's/-.*//; s/:/ /g; q' 2> /dev/null ) + if [ "cat ${jump}" != "" ]; then printf %s\\n "evaluate-commands -try-client '${kak_opt_jumpclient}' %{ - edit $(cat "${dir}/jump" ) + edit ${jump} }" fi - rm -r "${dir}" } } @@ -89,28 +86,13 @@ define-command -hidden -params 0 gopls-ref %{ mkfifo "${dir}/fifo" ( gopls references ${kak_buffile}:${kak_cursor_line}:${kak_cursor_column} \ > "${dir}/fifo" 2> /dev/null & ) > /dev/null 2>&1 < /dev/null + # using filetype=grep for nice hilight and mapping printf %s\\n "evaluate-commands -try-client '${kak_opt_toolsclient}' %{ edit! -fifo '${dir}/fifo' *gopls-refs* - set-option buffer filetype gopls + set-option buffer filetype grep hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r '${dir}' } } }" } } -hook global WinSetOption filetype=gopls %{ - hook buffer -group gopls-hooks NormalKey refs-jump - hook -once -always window WinSetOption filetype=.* %{ - remove-hooks buffer gopls-hooks - } -} - -define-command -hidden -params 0 refs-jump %{ - try %{ - execute-keys 's^((?:\w:)?[^:]+):(\d+):(\d+)?' - evaluate-commands -try-client %opt{jumpclient} -verbatim -- \ - edit -existing %reg{1} %reg{2} %reg{3} - try %{ focus %opt{jumpclient} } - } -} - ยง