Make the lint_errors a range-specs option in lint.kak

lint_errors are now maintained up to date with buffer changes.
This commit is contained in:
Maxime Coste 2017-05-25 19:31:56 +01:00
parent 26298e8f7b
commit f2f04d55fc

View File

@ -4,7 +4,7 @@ The output returned by this command is expected to comply with the following for
str lintcmd str lintcmd
decl -hidden line-specs lint_flags decl -hidden line-specs lint_flags
decl -hidden str lint_errors decl -hidden range-specs lint_errors
def lint -docstring 'Parse the current buffer with a linter' %{ def lint -docstring 'Parse the current buffer with a linter' %{
%sh{ %sh{
@ -42,16 +42,16 @@ def lint -docstring 'Parse the current buffer with a linter' %{
} }
} }
/:[0-9]+:[0-9]+:/ { /:[0-9]+:[0-9]+:/ {
errors = errors $2 "," $3 "," substr($4,2) ":" errors = errors ":" $2 "." $3 "," $2 "." $3 "|" substr($4,2)
# fix case where $5 is not the last field because of extra :s in the message # fix case where $5 is not the last field because of extra :s in the message
for (i=5; i<=NF; i++) errors = errors $i ":" for (i=5; i<=NF; i++) errors = errors "\\:" $i
errors = substr(errors, 1, length(errors)-1) " (col " $3 ")\n" errors = substr(errors, 1, length(errors)-1) " (col " $3 ")"
} }
END { END {
print "set \"buffer=" file "\" lint_flags %{" stamp ":" substr(flags, 1, length(flags)-1) "}" print "set \"buffer=" file "\" lint_flags %{" stamp ":" substr(flags, 1, length(flags)-1) "}"
errors = substr(errors, 1, length(errors)-1) errors = substr(errors, 1, length(errors)-1)
gsub("~", "\\~", errors) gsub("~", "\\~", errors)
print "set \"buffer=" file "\" lint_errors %~" errors "~" print "set \"buffer=" file "\" lint_errors %~" stamp errors "~"
} }
' "$dir"/stderr | kak -p "$kak_session" ' "$dir"/stderr | kak -p "$kak_session"
@ -61,12 +61,15 @@ def lint -docstring 'Parse the current buffer with a linter' %{
} }
} }
def -hidden lint-show %{ %sh{ def -hidden lint-show %{
desc=$(printf '%s\n' "$kak_opt_lint_errors" | sed -ne "/^$kak_cursor_line,.*/ { s/^[[:digit:]]*,[[:digit:]]*,//g; s/'/\\\\'/g; p; }") update-option buffer lint_errors
if [ -n "$desc" ]; then %sh{
printf '%s\n' "info -anchor $kak_cursor_line.$kak_cursor_column '$desc'" desc=$(printf '%s\n' "$kak_opt_lint_errors" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 |
fi sed -ne "/^$kak_cursor_line\.[^|]\+|.*/ { s/^[^|]\+|//g; s/'/\\\\'/g; s/\\\\:/:/g; p; }")
}} if [ -n "$desc" ]; then
printf '%s\n' "info -anchor $kak_cursor_line.$kak_cursor_column '$desc'"
fi
} }
def lint-enable -docstring "Activate automatic diagnostics of the code" %{ def lint-enable -docstring "Activate automatic diagnostics of the code" %{
add-highlighter flag_lines default lint_flags add-highlighter flag_lines default lint_flags
@ -78,48 +81,44 @@ def lint-disable -docstring "Disable automatic diagnostics of the code" %{
remove-hooks window lint-diagnostics remove-hooks window lint-diagnostics
} }
def lint-next -docstring "Jump to the next line that contains an error" %{ %sh{ def lint-next -docstring "Jump to the next line that contains an error" %{
printf '%s\n' "$kak_opt_lint_errors" | { update-option buffer lint_errors
while read -r line %sh{
do printf '%s\n' "$kak_opt_lint_errors" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 | {
# get line,column pair while IFS='|' read -r candidate rest
coords=$(printf %s "$line" | cut -d, -f1,2) do
candidate="${coords%,*}" first_range=${first_range-$candidate}
if [ "$candidate" -gt "$kak_cursor_line" ] if [ "${candidate%%.*}" -gt "$kak_cursor_line" ]; then
then range=$candidate
break break
fi
done
range=${range-$first_range}
if [ -n "$range" ]; then
printf '%s\n' "select $range"
else
printf 'echo -color Error no lint diagnostics\n'
fi fi
done }
if [ "$candidate" -gt "$kak_cursor_line" ] }}
then
col="${coords#*,}"
else
candidate="${kak_opt_lint_errors%%,*}"
col=$(printf '%s\n' "$kak_opt_lint_errors" | head -n1 | cut -d, -f2)
fi
printf '%s\n' "select $candidate.$col,$candidate.$col"
}
}}
def lint-prev -docstring "Jump to the previous line that contains an error" %{ %sh{ def lint-prev -docstring "Jump to the previous line that contains an error" %{
printf '%s\n' "$kak_opt_lint_errors" | sort -t, -k1,1 -rn | { update-option buffer lint_errors
while read -r line %sh{
do printf '%s\n' "$kak_opt_lint_errors" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 | sort -t. -k1,1 -rn | {
coords=$(printf %s "$line" | cut -d, -f1,2) while IFS='|' read -r candidate rest
candidate="${coords%,*}" do
if [ "$candidate" -lt "$kak_cursor_line" ] first_range=${first_range-$candidate}
then if [ "${candidate%%.*}" -lt "$kak_cursor_line" ]; then
break range=$candidate
break
fi
done
range=${range-$first_range}
if [ -n "$range" ]; then
printf '%s\n' "select $range"
else
printf 'echo -color Error no lint diagnostics\n'
fi fi
done }
if [ "$candidate" -lt "$kak_cursor_line" ] }}
then
col="${coords#*,}"
else
last=$(printf '%s\n' "$kak_opt_lint_errors" | tail -n1)
candidate=$(printf '%s\n' "$last" | cut -d, -f1)
col=$(printf '%s\n' "$last" | cut -d, -f2)
fi
printf '%s\n' "select $candidate.$col,$candidate.$col"
}
}}