Fix clang completion support with modern clang

This commit is contained in:
Maxime Coste 2019-09-15 11:48:25 +10:00
parent 90f83780a5
commit 33a00c7031

View File

@ -50,33 +50,33 @@ The syntaxic errors detected during parsing are shown when auto-diagnostics are
compl=$(clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} \ 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 | -Xclang -code-completion-brief-comments -Xclang -code-completion-at=${pos} - < ${dir}/buf 2> ${dir}/stderr |
awk -F ': ' ' awk -F ': ' '
/^COMPLETION:/ && ! /\(Hidden\)/ { /^COMPLETION:/ && $2 !~ /[(,](Hidden|Inaccessible)[),]/ {
id=$2 candidate=$3
gsub(/ +$/, "", id) gsub(/[[<{]#[^#]+#[]>}]/, "", candidate)
gsub(/~/, "~~", id) gsub(/~/, "~~", candidate)
gsub(/\|/, "\\|", id) gsub(/\|/, "\\|", candidate)
gsub(/[[{<]#|#[}>]/, "", $3) gsub(/[[{<]#|#[}>]/, "", $3)
gsub(/#]/, " ", $3) gsub(/#]/, " ", $3)
gsub(/:: /, "::", $3) gsub(/:: /, "::", $3)
gsub(/ +$/, "", $3) gsub(/ +$/, "", $3)
desc=$4 ? $3 "\n" $4 : $3 docstring=$4 ? $3 "\n" $4 : $3
gsub(/~/, "~~", desc) gsub(/~/, "~~", docstring)
gsub(/!/, "!!", desc) gsub(/!/, "!!", docstring)
gsub(/\|/, "\\|", desc) gsub(/\|/, "\\|", docstring)
if (id in docstrings) if (candidate in candidates)
docstrings[id]=docstrings[id] "\n" desc candidates[candidate]=candidates[candidate] "\n" docstring
else else
docstrings[id]=desc candidates[candidate]=docstring
} }
END { END {
for (id in docstrings) { for (candidate in candidates) {
menu=id menu=candidate
gsub(/(^|[^[:alnum:]_])(operator|new|delete)($|[^{}_[:alnum:]]+)/, "{keyword}&{}", menu) gsub(/(^|[^[:alnum:]_])(operator|new|delete)($|[^{}_[:alnum:]]+)/, "{keyword}&{}", menu)
gsub(/(^|[[:space:]])(int|size_t|bool|char|unsigned|signed|long)($|[[:space:]])/, "{type}&{}", menu) gsub(/(^|[[:space:]])(int|size_t|bool|char|unsigned|signed|long)($|[[:space:]])/, "{type}&{}", menu)
gsub(/[^{}_[:alnum:]]+/, "{operator}&{}", menu) gsub(/[^{}_[:alnum:]]+/, "{operator}&{}", menu)
printf "%%~%s|info -style menu %!%s!|%s~ ", id, docstrings[id], menu printf "%%~%s|info -style menu %!%s!|%s~ ", candidate, candidates[candidate], menu
} }
}') }')
printf %s\\n "evaluate-commands -client ${kak_client} echo 'clang completion done' printf %s\\n "evaluate-commands -client ${kak_client} echo 'clang completion done'