Clean racer support functions

This commit is contained in:
Marc 2018-03-14 15:56:25 +00:00
parent 2f41fdb683
commit 2bf8941d99

View File

@ -102,20 +102,18 @@ define-command racer-go-definition -docstring "Jump to where the rust identifier
} }
%sh{ %sh{
dir=${kak_opt_racer_tmp_dir} dir=${kak_opt_racer_tmp_dir}
(
cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))" cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))"
racer_data=$(racer --interface tab-text find-definition ${cursor} ${kak_buffile} ${dir}/buf | head -n 1) racer_data=$(racer --interface tab-text find-definition ${cursor} "${kak_buffile}" "${dir}/buf" | head -n 1)
racer_match=$(printf %s\\n "$racer_data" | cut -f1 ) racer_match=$(printf %s\\n "$racer_data" | cut -f1 )
if [[ "$racer_match" == "MATCH" ]]; then if [ "$racer_match" = "MATCH" ]; then
racer_line=$(printf %s\\n "$racer_data" | cut -f3 ) racer_line=$(printf %s\\n "$racer_data" | cut -f3 )
racer_column=$(printf %s\\n "$racer_data" | cut -f4 ) racer_column=$(printf %s\\n "$racer_data" | cut -f4 )
racer_file=$(printf %s\\n "$racer_data" | cut -f5 ) racer_file=$(printf %s\\n "$racer_data" | cut -f5 )
printf %s\\n "edit -existing '$racer_file' $racer_line $racer_column" printf %s\\n "edit -existing '$racer_file' $racer_line $racer_column"
printf %s\\n "set-option buffer readonly true" #printf %s\\n "set-option buffer readonly true"
else else
printf %s\\n "echo -debug 'racer could not find a definition'" printf %s\\n "echo -debug 'racer could not find a definition'"
fi fi
)
} }
} }
@ -127,20 +125,16 @@ define-command racer-show-doc -docstring "Show the documentation about the rust
} }
%sh{ %sh{
dir=${kak_opt_racer_tmp_dir} dir=${kak_opt_racer_tmp_dir}
(
printf -v NEWLINE '\n'
cursor="${kak_cursor_line} ${kak_cursor_column}" cursor="${kak_cursor_line} ${kak_cursor_column}"
racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} ${kak_buffile} ${dir}/buf | head -n 2 | tail -n 1) racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} "${kak_buffile}" "${dir}/buf" | head -n 2 | tail -n 1)
racer_match=$(printf %s\\n "$racer_data" | cut -f1) racer_match=$(printf %s\\n "$racer_data" | cut -f1)
printf %s\\n "info %@.$racer_match.@" if [ "$racer_match" = "MATCH" ]; then
if [[ "$racer_match" == "MATCH" ]]; then racer_doc=$(printf %s\\n "$racer_data" | cut -f9 )
racer_doc=$(printf %s\\n "$racer_data" | cut -f9 | xargs ) racer_doc=$(printf %s\\n "$racer_doc" | sed -e 's/^"\(.*\)"$/\1/g')
racer_doc=$(printf %s\\n "$racer_doc" | sed -e "s/\\\n/\\$NEWLINE/g") racer_doc=$(printf %s\\n "$racer_doc" | sed -e "s/@/\\\\@/g")
racer_doc=$(printf %s\\n "$racer_doc" | sed -e "s/@/\\@/g") printf "info %%@$racer_doc@"
printf %s\\n "info %@$racer_doc@"
else else
printf %s\\n "echo -debug 'racer could not find a definition'" printf %s\\n "echo -debug 'racer could not find a definition'"
fi fi
)
} }
} }