gopls: fixes based on krobelus@ review

This commit is contained in:
VÖRÖSKŐI András 2020-09-16 21:58:22 +02:00
parent 2b18b1d088
commit 9fe1a2a9a4

View File

@ -1,7 +1,7 @@
# gopls.kak: gopls bindings for kakoune # gopls.kak: gopls bindings for kakoune
define-command -params 1 -docstring %{ define-command -params 1 -docstring %{
gopls <command>: gopls command wrapper for kakoune gopls <command>: gopls command wrapper
All commands are forwarded to gopls utility All commands are forwarded to gopls utility
Available commands are: Available commands are:
@ -41,7 +41,7 @@ evaluate-commands %sh{
fi fi
} }
# Temp dir prepatation # Temp dir preparation
declare-option -hidden str gopls_tmp_dir declare-option -hidden str gopls_tmp_dir
define-command -hidden -params 0 gopls-prepare %{ define-command -hidden -params 0 gopls-prepare %{
evaluate-commands %sh{ evaluate-commands %sh{
@ -55,7 +55,7 @@ define-command -hidden -params 1 gopls-cmd %{
gopls-prepare gopls-prepare
evaluate-commands %sh{ evaluate-commands %sh{
dir=${kak_opt_gopls_tmp_dir} 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 if [ $? -ne 0 ]; then
# show error messages in *debug* buffer # show error messages in *debug* buffer
printf %s\\n "echo -debug %file{ '${dir}/stderr' }" printf %s\\n "echo -debug %file{ '${dir}/stderr' }"
@ -67,17 +67,14 @@ define-command -hidden -params 1 gopls-cmd %{
# gopls definition # gopls definition
define-command -hidden -params 0 gopls-def %{ define-command -hidden -params 0 gopls-def %{
gopls-prepare
evaluate-commands %sh{ evaluate-commands %sh{
dir=${kak_opt_gopls_tmp_dir} jump=$( gopls definition ${kak_buffile}:${kak_cursor_line}:${kak_cursor_column} \
eval "gopls definition ${kak_buffile}:${kak_cursor_line}:${kak_cursor_column} \ |sed -e 's/-.*//; s/:/ /g; q' 2> /dev/null )
|sed -e 's/-.*//' -e 's/:/ /g' > '${dir}/jump'" if [ "cat ${jump}" != "" ]; then
if [ -s "${dir}/jump" ]; then
printf %s\\n "evaluate-commands -try-client '${kak_opt_jumpclient}' %{ printf %s\\n "evaluate-commands -try-client '${kak_opt_jumpclient}' %{
edit $(cat "${dir}/jump" ) edit ${jump}
}" }"
fi fi
rm -r "${dir}"
} }
} }
@ -89,28 +86,13 @@ define-command -hidden -params 0 gopls-ref %{
mkfifo "${dir}/fifo" mkfifo "${dir}/fifo"
( gopls references ${kak_buffile}:${kak_cursor_line}:${kak_cursor_column} \ ( gopls references ${kak_buffile}:${kak_cursor_line}:${kak_cursor_column} \
> "${dir}/fifo" 2> /dev/null & ) > /dev/null 2>&1 < /dev/null > "${dir}/fifo" 2> /dev/null & ) > /dev/null 2>&1 < /dev/null
# using filetype=grep for nice hilight and <ret> mapping
printf %s\\n "evaluate-commands -try-client '${kak_opt_toolsclient}' %{ printf %s\\n "evaluate-commands -try-client '${kak_opt_toolsclient}' %{
edit! -fifo '${dir}/fifo' *gopls-refs* 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 -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r '${dir}' } }
}" }"
} }
} }
hook global WinSetOption filetype=gopls %{
hook buffer -group gopls-hooks NormalKey <ret> refs-jump
hook -once -always window WinSetOption filetype=.* %{
remove-hooks buffer gopls-hooks
}
}
define-command -hidden -params 0 refs-jump %{
try %{
execute-keys '<a-x>s^((?:\w:)?[^:]+):(\d+):(\d+)?<ret>'
evaluate-commands -try-client %opt{jumpclient} -verbatim -- \
edit -existing %reg{1} %reg{2} %reg{3}
try %{ focus %opt{jumpclient} }
}
}
§ §