Get non completion clang output into a buffer when completing
This commit is contained in:
parent
54f4b8fc2d
commit
cd24bf93e8
22
rc/clang.kak
22
rc/clang.kak
|
@ -1,24 +1,32 @@
|
||||||
decl str clang_options
|
decl str clang_options
|
||||||
|
|
||||||
decl -hidden str clang_filename
|
decl -hidden str clang_tmp_dir
|
||||||
decl -hidden str-list clang_completions
|
decl -hidden str-list clang_completions
|
||||||
|
|
||||||
def clang-complete %{
|
def clang-complete %{
|
||||||
%sh{
|
%sh{
|
||||||
filename=$(mktemp -d -t kak-clang.XXXXXXXX)/buffer.cpp
|
dir=$(mktemp -d -t kak-clang.XXXXXXXX)
|
||||||
echo "set buffer clang_filename $filename"
|
mkfifo ${dir}/fifo
|
||||||
echo "write $filename"
|
echo "set buffer clang_tmp_dir ${dir}"
|
||||||
|
echo "write ${dir}/buffer.cpp"
|
||||||
}
|
}
|
||||||
# end the previous %sh{} so that its output gets interpreted by kakoune
|
# end the previous %sh{} so that its output gets interpreted by kakoune
|
||||||
# before launching the following as a background task.
|
# before launching the following as a background task.
|
||||||
%sh{
|
%sh{
|
||||||
|
dir=${kak_opt_clang_tmp_dir}
|
||||||
|
echo "eval -draft %{
|
||||||
|
edit! -fifo ${dir}/fifo *clang-output*
|
||||||
|
set buffer filetype make
|
||||||
|
set buffer _make_current_error_line 0
|
||||||
|
hook buffer BufCloseFifo .* %{ nop %sh{ rm -r ${dir} } }
|
||||||
|
}"
|
||||||
# this runs in a detached shell, asynchronously, so that kakoune does not hang while clang is running.
|
# this runs in a detached shell, asynchronously, so that kakoune does not hang while clang is running.
|
||||||
# As completions references a cursor position and a buffer timestamp, only valid completions should be
|
# As completions references a cursor position and a buffer timestamp, only valid completions should be
|
||||||
# displayed.
|
# displayed.
|
||||||
(
|
(
|
||||||
pos=-:${kak_cursor_line}:${kak_cursor_column}
|
pos=-:${kak_cursor_line}:${kak_cursor_column}
|
||||||
cd $(dirname ${kak_buffile})
|
cd $(dirname ${kak_buffile})
|
||||||
clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${kak_opt_clang_filename} 2>&1 | awk -e '
|
clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${dir}/buffer.cpp 2>&1 | awk -e '
|
||||||
function rmblocks(opening, closing, val, res) {
|
function rmblocks(opening, closing, val, res) {
|
||||||
while (match(val, opening)) {
|
while (match(val, opening)) {
|
||||||
res = res substr(val, 1, RSTART-1)
|
res = res substr(val, 1, RSTART-1)
|
||||||
|
@ -35,11 +43,11 @@ def clang-complete %{
|
||||||
gsub("\\((, )+\\)", "(", c); gsub("<(, )+>", "<", c)
|
gsub("\\((, )+\\)", "(", c); gsub("<(, )+>", "<", c)
|
||||||
out = out ":" c
|
out = out ":" c
|
||||||
}
|
}
|
||||||
|
! /^COMPLETION:[^:]+:/ { print $0 }
|
||||||
END {
|
END {
|
||||||
cmd = "kak -p " ENVIRON["kak_session"]
|
cmd = "kak -p " ENVIRON["kak_session"]
|
||||||
print "eval -client " ENVIRON["kak_client"] " %[ echo completed; set buffer clang_completions %[" out "] ]" | cmd
|
print "eval -client " ENVIRON["kak_client"] " %[ echo completed; set buffer clang_completions %[" out "] ]" | cmd
|
||||||
}'
|
}' 2>&1 > ${dir}/fifo
|
||||||
rm -r $(dirname ${kak_opt_clang_filename})
|
|
||||||
) > /dev/null 2>&1 < /dev/null &
|
) > /dev/null 2>&1 < /dev/null &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user