From 26298e8f7b7325dd827340bbe45482e4e5654301 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 25 May 2017 12:17:22 +0100 Subject: [PATCH] Use a line-specs for the clang_errors option in clang.kak That way, we can have it updated when the buffer changes, and get diagnostics on the correct lines. --- rc/extra/clang.kak | 62 +++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/rc/extra/clang.kak b/rc/extra/clang.kak index 71ddd7955..7636dbc37 100644 --- a/rc/extra/clang.kak +++ b/rc/extra/clang.kak @@ -4,7 +4,7 @@ decl -docstring "options to pass to the `clang` shell command" \ decl -hidden str clang_tmp_dir decl -hidden completions clang_completions decl -hidden line-specs clang_flags -decl -hidden str clang_errors +decl -hidden line-specs clang_errors def -params ..1 \ -docstring %{Parse the contents of the current buffer @@ -88,13 +88,15 @@ The syntaxic errors detected during parsing are shown when auto-diagnostics are " | paste -s -d ':' -) errors=$(cat ${dir}/stderr | sed -rne " - /^:[0-9]+:([0-9]+:)? ((fatal )?error|warning)/ { s/^:([0-9]+):([0-9]+:)? (.*)/\1,\3/; s/'/\\\\'/g; p } - " | sort -n) + /^:[0-9]+:([0-9]+:)? ((fatal )?error|warning)/ { + s/^:([0-9]+):([0-9]+:)? (.*)/\1|\3/ + s/'/\\\\'/g; s/:/\\\\:/g; p + }" | sort -n | paste -s -d ':' -) sed -e "s||${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo printf %s\\n "set 'buffer=${kak_buffile}' clang_flags %{${kak_timestamp}:${flags}} - set 'buffer=${kak_buffile}' clang_errors '${errors}'" | kak -p ${kak_session} + set 'buffer=${kak_buffile}' clang_errors '${kak_timestamp}:${errors}'" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } } @@ -131,12 +133,16 @@ def clang-disable-autocomplete -docstring "Disable automatic clang completion" % unalias window complete clang-complete } -def -hidden clang-show-error-info %{ %sh{ - desc=$(printf %s\\n "${kak_opt_clang_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }") - if [ -n "$desc" ]; then - printf %s\\n "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" - fi -} } +def -hidden clang-show-error-info %{ + update-option buffer clang_errors # Ensure we are up to date with buffer changes + %sh{ + desc=$(printf %s\\n "${kak_opt_clang_errors}" | + sed -e "s/\([^\\]\):/\1\n/g" | + sed -ne "/^${kak_cursor_line}|.*/ { s/^[[:digit:]]\+|//g; s/'/\\\\'/g; s/\\\\:/:/g; p }") + if [ -n "$desc" ]; then + printf %s\\n "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" + fi + } } def clang-enable-diagnostics -docstring %{Activate automatic error reporting and diagnostics Information about the analysis are showned after the buffer has been parsed with the clang-parse function} \ @@ -151,22 +157,22 @@ def clang-disable-diagnostics -docstring "Disable automatic error reporting and remove-hooks window clang-diagnostics } -def clang-diagnostics-next -docstring "Jump to the next line that contains an error" %{ %sh{ - printf "%s\n" "${kak_opt_clang_errors}" | ( - line=-1 - first_line=-1 - while read line_content; do - candidate=${line_content%%,*} - if [ -n "$candidate" ]; then - first_line=$(( first_line == -1 ? candidate : first_line )) - line=$((candidate > kak_cursor_line && (candidate < line || line == -1) ? candidate : line )) +def clang-diagnostics-next -docstring "Jump to the next line that contains an error" %{ + update-option buffer clang_errors # Ensure we are up to date with buffer changes + %sh{ + printf "%s\n" "${kak_opt_clang_errors}" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 | ( + while IFS='|' read candidate rest; do + first_line=${first_line-$candidate} + if [ $candidate -gt $kak_cursor_line ]; then + line=$candidate + break + fi + done + line=${line-$first_line} + if [ -n "$line" ]; then + printf %s\\n "exec ${line} g" + else + echo 'echo -color Error no next clang diagnostic' fi - done - line=$((line == -1 ? first_line : line)) - if [ ${line} -ne -1 ]; then - printf %s\\n "exec ${line} g" - else - echo 'echo -color Error no next clang diagnostic' - fi - ) -} } + ) + } }