gopls: fixes based on krobelus@ review
This commit is contained in:
parent
2b18b1d088
commit
9fe1a2a9a4
|
@ -1,7 +1,7 @@
|
|||
# gopls.kak: gopls bindings for kakoune
|
||||
|
||||
define-command -params 1 -docstring %{
|
||||
gopls <command>: gopls command wrapper for kakoune
|
||||
gopls <command>: 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 <ret> 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 <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} }
|
||||
}
|
||||
}
|
||||
|
||||
§
|
||||
|
|
Loading…
Reference in New Issue
Block a user