2013-03-14 17:12:14 +04:00
|
|
|
decl str clang_options
|
2014-04-03 22:00:42 +04:00
|
|
|
|
2014-10-24 21:46:42 +04:00
|
|
|
decl -hidden str clang_tmp_dir
|
2014-04-03 22:00:42 +04:00
|
|
|
decl -hidden str-list clang_completions
|
2014-11-19 16:53:31 +03:00
|
|
|
decl -hidden line-flag-list clang_flags
|
|
|
|
decl -hidden str clang_errors
|
2013-03-14 17:12:14 +04:00
|
|
|
|
2014-11-27 16:42:36 +03:00
|
|
|
def -shell-params clang-parse %{
|
2013-03-14 17:12:14 +04:00
|
|
|
%sh{
|
2014-10-24 21:46:42 +04:00
|
|
|
dir=$(mktemp -d -t kak-clang.XXXXXXXX)
|
|
|
|
mkfifo ${dir}/fifo
|
|
|
|
echo "set buffer clang_tmp_dir ${dir}"
|
2014-10-31 23:53:36 +03:00
|
|
|
echo "write ${dir}/buf"
|
2013-03-14 17:12:14 +04:00
|
|
|
}
|
|
|
|
# end the previous %sh{} so that its output gets interpreted by kakoune
|
|
|
|
# before launching the following as a background task.
|
|
|
|
%sh{
|
2014-10-24 21:46:42 +04:00
|
|
|
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
|
|
|
|
}"
|
2014-11-06 22:17:13 +03:00
|
|
|
# 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
|
2013-03-14 17:12:14 +04:00
|
|
|
# displayed.
|
|
|
|
(
|
2015-02-18 16:55:47 +03:00
|
|
|
trap "rm -r ${dir}" EXIT
|
|
|
|
|
2014-11-21 16:27:43 +03:00
|
|
|
case ${kak_opt_filetype} in
|
|
|
|
cpp) ft=c++ ;;
|
|
|
|
obj-c) ft=objective-c ;;
|
|
|
|
*) ft=c++ ;;
|
|
|
|
esac
|
|
|
|
|
2014-03-02 05:07:29 +04:00
|
|
|
cd $(dirname ${kak_buffile})
|
2014-11-27 16:42:36 +03:00
|
|
|
if [ "$1" == "-complete" ]; then
|
2015-02-03 03:42:40 +03:00
|
|
|
pos=-:${kak_cursor_line}:${kak_cursor_column}
|
|
|
|
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
|
|
|
compl=$(clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} \
|
|
|
|
-Xclang -code-completion-brief-comments -Xclang -code-completion-at=${pos} - < ${dir}/buf 2> ${dir}/stderr |
|
|
|
|
awk -F ': ' -e '
|
|
|
|
/^COMPLETION:/ && ! /\(Hidden\)/ {
|
|
|
|
gsub(/[[{<]#|#[}>]/, "", $3)
|
|
|
|
gsub(/#]/, " ", $3)
|
|
|
|
gsub(/:: /, "::", $3)
|
|
|
|
gsub(/ +$/, "", $3)
|
|
|
|
id=substr($2, 1, length($2)-1)
|
|
|
|
gsub(/:/, "\\:", id)
|
|
|
|
gsub(/"/, "\\\"", id)
|
|
|
|
desc=$4 ? $3 "\\n" $4 : $3
|
|
|
|
gsub(/:/, "\\:", desc)
|
|
|
|
gsub(/"/, "\\\"", desc)
|
|
|
|
if (id in completions)
|
|
|
|
completions[id]=completions[id] "\\n" desc
|
|
|
|
else
|
|
|
|
completions[id]=desc
|
|
|
|
}
|
|
|
|
END {
|
|
|
|
for (id in completions)
|
|
|
|
print id "@" completions[id]
|
|
|
|
}' | sort | paste -s -d ':' | sed -e 's/\\n/\n/g')
|
|
|
|
echo "eval -client ${kak_client} echo completed
|
|
|
|
set 'buffer=${kak_buffile}' clang_completions \"${header}:${compl}\"" | kak -p ${kak_session}
|
2014-11-27 16:42:36 +03:00
|
|
|
else
|
2015-02-03 03:42:40 +03:00
|
|
|
clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} - < ${dir}/buf 2> ${dir}/stderr
|
2014-11-27 16:42:36 +03:00
|
|
|
fi
|
2014-10-31 23:53:36 +03:00
|
|
|
|
2014-11-27 16:42:36 +03:00
|
|
|
flags=$(cat ${dir}/stderr | sed -rne "
|
2014-11-19 16:53:31 +03:00
|
|
|
/^<stdin>:[0-9]+:([0-9]+:)? error/ { s/^<stdin>:([0-9]+):.*/\1,red,█/; p }
|
|
|
|
/^<stdin>:[0-9]+:([0-9]+:)? warning/ { s/^<stdin>:([0-9]+):.*/\1,yellow,█/; p }
|
|
|
|
" | paste -s -d ':')
|
|
|
|
|
2014-11-27 16:42:36 +03:00
|
|
|
errors=$(cat ${dir}/stderr | sed -rne "
|
2015-02-18 16:55:47 +03:00
|
|
|
/^<stdin>:[0-9]+:([0-9]+:)? (error|warning)/ { s/^<stdin>:([0-9]+):([0-9]+:)? (.*)/\1,\3/; s/'/\\\\'/g; p }")
|
2014-11-19 16:53:31 +03:00
|
|
|
|
2014-11-27 16:42:36 +03:00
|
|
|
sed -e "s|<stdin>|${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo
|
2014-11-19 16:53:31 +03:00
|
|
|
|
2014-11-27 16:42:36 +03:00
|
|
|
echo "set 'buffer=${kak_buffile}' clang_flags %{${flags}}
|
2015-02-18 16:55:47 +03:00
|
|
|
set 'buffer=${kak_buffile}' clang_errors '${errors}'" | kak -p ${kak_session}
|
2014-03-06 07:35:38 +04:00
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
2013-03-14 17:12:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 16:42:36 +03:00
|
|
|
def clang-complete %{ clang-parse -complete }
|
|
|
|
|
2013-03-14 17:12:14 +04:00
|
|
|
def clang-enable-autocomplete %{
|
2014-11-11 16:53:57 +03:00
|
|
|
set window completers "option=clang_completions:%opt{completers}"
|
2014-06-16 23:42:12 +04:00
|
|
|
hook window -group clang-autocomplete InsertIdle .* %{ try %{
|
2014-10-30 03:50:09 +03:00
|
|
|
exec -draft <a-h><a-k>(\.|->|::).\'<ret>
|
2013-10-31 23:14:44 +04:00
|
|
|
echo 'completing...'
|
|
|
|
clang-complete
|
2013-11-07 22:50:16 +04:00
|
|
|
} }
|
2014-11-18 16:55:52 +03:00
|
|
|
alias window complete clang-complete
|
2013-03-14 17:12:14 +04:00
|
|
|
}
|
2013-04-11 16:30:02 +04:00
|
|
|
|
2014-03-15 07:14:23 +04:00
|
|
|
def clang-disable-autocomplete %{
|
|
|
|
set window completers %sh{ echo "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' }
|
|
|
|
rmhooks window clang-autocomplete
|
2014-11-18 16:55:52 +03:00
|
|
|
unalias window complete clang-complete
|
2014-03-15 07:14:23 +04:00
|
|
|
}
|
2014-11-19 16:53:31 +03:00
|
|
|
|
|
|
|
def -hidden clang-show-error-info %{ %sh{
|
|
|
|
echo "${kak_opt_clang_errors}" | while read line; do
|
|
|
|
case "${line}" in
|
|
|
|
${kak_cursor_line},*) echo "info -anchor ${kak_cursor_line}.${kak_cursor_column} %{${line#*,}}" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
} }
|
|
|
|
|
|
|
|
def clang-enable-diagnostics %{
|
|
|
|
addhl flag_lines default clang_flags
|
|
|
|
hook window -group clang-diagnostics NormalIdle .* %{ clang-show-error-info }
|
|
|
|
}
|
|
|
|
|
|
|
|
def clang-disable-diagnostics %{
|
|
|
|
rmhl hlflags_clang_flags
|
|
|
|
rmhooks window clang-diagnostics
|
|
|
|
}
|