make clang useable just for syntax checking with clang-parse command
This commit is contained in:
parent
45d1ec36d1
commit
1f89509df9
69
rc/clang.kak
69
rc/clang.kak
|
@ -5,7 +5,7 @@ decl -hidden str-list clang_completions
|
||||||
decl -hidden line-flag-list clang_flags
|
decl -hidden line-flag-list clang_flags
|
||||||
decl -hidden str clang_errors
|
decl -hidden str clang_errors
|
||||||
|
|
||||||
def clang-complete %{
|
def -shell-params clang-parse %{
|
||||||
%sh{
|
%sh{
|
||||||
dir=$(mktemp -d -t kak-clang.XXXXXXXX)
|
dir=$(mktemp -d -t kak-clang.XXXXXXXX)
|
||||||
mkfifo ${dir}/fifo
|
mkfifo ${dir}/fifo
|
||||||
|
@ -32,52 +32,57 @@ def clang-complete %{
|
||||||
*) ft=c++ ;;
|
*) ft=c++ ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
pos=-:${kak_cursor_line}:${kak_cursor_column}
|
|
||||||
cd $(dirname ${kak_buffile})
|
cd $(dirname ${kak_buffile})
|
||||||
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
if [ "$1" == "-complete" ]; then
|
||||||
compl=$(clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-brief-comments -Xclang -code-completion-at=${pos} - < ${dir}/buf 2> ${dir}/errors |
|
pos=-:${kak_cursor_line}:${kak_cursor_column}
|
||||||
awk -F ': ' -e '
|
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
||||||
/^COMPLETION:/ && ! /\(Hidden\)/ {
|
compl=$(clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} \
|
||||||
gsub(/[[{<]#|#[}>]/, "", $3)
|
-Xclang -code-completion-brief-comments -Xclang -code-completion-at=${pos} - < ${dir}/buf 2> ${dir}/stderr |
|
||||||
gsub(/#]/, " ", $3)
|
awk -F ': ' -e '
|
||||||
gsub(/:: /, "::", $3)
|
/^COMPLETION:/ && ! /\(Hidden\)/ {
|
||||||
gsub(/ +$/, "", $3)
|
gsub(/[[{<]#|#[}>]/, "", $3)
|
||||||
id=substr($2, 1, length($2)-1)
|
gsub(/#]/, " ", $3)
|
||||||
gsub(/:/, "\\:", id)
|
gsub(/:: /, "::", $3)
|
||||||
desc=$4 ? $3 "\\n" $4 : $3
|
gsub(/ +$/, "", $3)
|
||||||
gsub(/:/, "\\:", desc)
|
id=substr($2, 1, length($2)-1)
|
||||||
if (id in completions)
|
gsub(/:/, "\\:", id)
|
||||||
completions[id]=completions[id] "\\n" desc
|
desc=$4 ? $3 "\\n" $4 : $3
|
||||||
else
|
gsub(/:/, "\\:", desc)
|
||||||
completions[id]=desc
|
if (id in completions)
|
||||||
}
|
completions[id]=completions[id] "\\n" desc
|
||||||
END {
|
else
|
||||||
for (id in completions)
|
completions[id]=desc
|
||||||
print id "@" completions[id]
|
}
|
||||||
}' | sort | paste -s -d ':' | sed -e 's/\\n/\n/g')
|
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}
|
||||||
|
else
|
||||||
|
clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} - < ${dir}/buf 2> ${dir}/stderr
|
||||||
|
fi
|
||||||
|
|
||||||
flags=$(cat ${dir}/errors | sed -rne "
|
flags=$(cat ${dir}/stderr | sed -rne "
|
||||||
/^<stdin>:[0-9]+:([0-9]+:)? error/ { s/^<stdin>:([0-9]+):.*/\1,red,█/; p }
|
/^<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 }
|
/^<stdin>:[0-9]+:([0-9]+:)? warning/ { s/^<stdin>:([0-9]+):.*/\1,yellow,█/; p }
|
||||||
" | paste -s -d ':')
|
" | paste -s -d ':')
|
||||||
|
|
||||||
errors=$(cat ${dir}/errors | sed -rne "
|
errors=$(cat ${dir}/stderr | sed -rne "
|
||||||
/^<stdin>:[0-9]+:([0-9]+:)? (error|warning)/ { s/^<stdin>:([0-9]+):([0-9]+:)? (.*)/\1,\3/; p }")
|
/^<stdin>:[0-9]+:([0-9]+:)? (error|warning)/ { s/^<stdin>:([0-9]+):([0-9]+:)? (.*)/\1,\3/; p }")
|
||||||
|
|
||||||
sed -e "s|<stdin>|${kak_bufname}|g" < ${dir}/errors > ${dir}/fifo
|
sed -e "s|<stdin>|${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo
|
||||||
|
|
||||||
echo "eval -client ${kak_client} %[
|
echo "set 'buffer=${kak_buffile}' clang_flags %{${flags}}
|
||||||
echo completed
|
set 'buffer=${kak_buffile}' clang_errors %{${errors}}" | kak -p ${kak_session}
|
||||||
set 'buffer=${kak_buffile}' clang_completions %[${header}:${compl}] ]
|
|
||||||
set 'buffer=${kak_buffile}' clang_flags %{${flags}}
|
|
||||||
set 'buffer=${kak_buffile}' clang_errors %{${errors}}
|
|
||||||
" | kak -p ${kak_session}
|
|
||||||
|
|
||||||
rm -r ${dir}
|
rm -r ${dir}
|
||||||
) > /dev/null 2>&1 < /dev/null &
|
) > /dev/null 2>&1 < /dev/null &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def clang-complete %{ clang-parse -complete }
|
||||||
|
|
||||||
def clang-enable-autocomplete %{
|
def clang-enable-autocomplete %{
|
||||||
set window completers "option=clang_completions:%opt{completers}"
|
set window completers "option=clang_completions:%opt{completers}"
|
||||||
hook window -group clang-autocomplete InsertIdle .* %{ try %{
|
hook window -group clang-autocomplete InsertIdle .* %{ try %{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user