Fix clang.kak and part of lint.kak

* Make clang.kak compatible with POSIX `[`.
* Make lint.kak dump range/line-specs correctly. It still doesn't read them
  correctly -- that'll be easier after the upcoming $kak_ changes for lists.
This commit is contained in:
Shachaf Ben-Kiki 2018-06-20 15:46:38 -07:00 committed by Maxime Coste
parent 7f117dff1e
commit 1a2eecd037
2 changed files with 12 additions and 10 deletions

View File

@ -29,35 +29,37 @@ define-command lint -docstring 'Parse the current buffer with a linter' %{
eval "$kak_opt_lintcmd '$dir'/buf" | sort -t: -k2,2 -n > "$dir"/stderr eval "$kak_opt_lintcmd '$dir'/buf" | sort -t: -k2,2 -n > "$dir"/stderr
# Flags for the gutter: # Flags for the gutter:
# stamp:l3|{red}█:l11|{yellow}█ # stamp l3|{red}█ l11|{yellow}█
# Contextual error messages: # Contextual error messages:
# stamp:l1.c1,l1.c1|kind\:message:l2.c2,l2.c2|kind\:message # stamp 'l1.c1,l1.c1|kind:message' 'l2.c2,l2.c2|kind:message'
awk -F: -v file="$kak_buffile" -v stamp="$kak_timestamp" -v client="$kak_client" ' awk -F: -v file="$kak_buffile" -v stamp="$kak_timestamp" -v client="$kak_client" '
BEGIN { BEGIN {
error_count = 0 error_count = 0
warning_count = 0 warning_count = 0
} }
/:[0-9]+:[0-9]+: ([Ff]atal )?[Ee]rror/ { /:[0-9]+:[0-9]+: ([Ff]atal )?[Ee]rror/ {
flags = flags ":" $2 "|{red}█" flags = flags " " $2 "|{red}█"
error_count++ error_count++
} }
/:[0-9]+:[0-9]+:/ { /:[0-9]+:[0-9]+:/ {
if ($4 !~ /[Ee]rror/) { if ($4 !~ /[Ee]rror/) {
flags = flags ":" $2 "|{yellow}█" flags = flags " " $2 "|{yellow}█"
warning_count++ warning_count++
} }
} }
/:[0-9]+:[0-9]+:/ { /:[0-9]+:[0-9]+:/ {
kind = substr($4, 2) kind = substr($4, 2)
errors = errors ":" $2 "." $3 "," $2 "." $3 "|" kind error = $2 "." $3 "," $2 "." $3 "|" kind
# fix case where $5 is not the last field because of extra colons in the message # fix case where $5 is not the last field because of extra colons in the message
for (i=5; i<=NF; i++) errors = errors "\\:" $i for (i=5; i<=NF; i++) error = error "\\:" $i
errors = errors " (col " $3 ")" error = error " (col " $3 ")"
gsub("'\''", "'"''"'", error)
errors = errors " '\''" error "'\''"
} }
END { END {
print "set-option \"buffer=" file "\" lint_flags %{" stamp flags "}" print "set-option \"buffer=" file "\" lint_flags " stamp flags
gsub("~", "\\~", errors) gsub("~", "\\~", errors)
print "set-option \"buffer=" file "\" lint_errors %~" stamp errors "~" print "set-option \"buffer=" file "\" lint_errors " stamp errors
print "set-option \"buffer=" file "\" lint_error_count " error_count print "set-option \"buffer=" file "\" lint_error_count " error_count
print "set-option \"buffer=" file "\" lint_warning_count " warning_count print "set-option \"buffer=" file "\" lint_warning_count " warning_count
print "evaluate-commands -client " client " lint-show-counters" print "evaluate-commands -client " client " lint-show-counters"

View File

@ -138,7 +138,7 @@ define-command -hidden clang-show-error-info %{
eval "set -- ${kak_opt_clang_errors}" eval "set -- ${kak_opt_clang_errors}"
shift # skip timestamp shift # skip timestamp
for error in "$@"; do for error in "$@"; do
if [ "${error%%|*}" == "$kak_cursor_line" ]; then if [ "${error%%|*}" = "$kak_cursor_line" ]; then
desc=$(printf '%s%s\n' "$desc" "${error##*|}") desc=$(printf '%s%s\n' "$desc" "${error##*|}")
fi fi
done done