From dbf530e87fde81397712a85ed87b6a15131afd4c Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 23 Mar 2018 12:17:49 +0000 Subject: [PATCH] Fix #1373 - Fix a bug with Fish errors not being handled on Linux --- ale_linters/fish/fish.vim | 59 +++++++++++++++++++++------- test/handler/test_fish_handler.vader | 22 +++++++++++ 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/ale_linters/fish/fish.vim b/ale_linters/fish/fish.vim index 19158cb0..87ede29a 100644 --- a/ale_linters/fish/fish.vim +++ b/ale_linters/fish/fish.vim @@ -7,22 +7,53 @@ function! ale_linters#fish#fish#Handle(buffer, lines) abort " home/.config/fish/functions/foo.fish (line 1): Missing end to balance this function definition " function foo " ^ - " fish: Error while reading file .config/fish/functions/foo.fish - let l:pattern = '^.* (line \(\d\+\)): \(.*\)$' + " + " OR, patterns such as: + " + " Unsupported use of '||'. In fish, please use 'COMMAND; or COMMAND'. + " /tmp/vLz620o/258/test.fish (line 2): if set -q SSH_CLIENT || set -q SSH_TTY + " ^ + " + " fish -n can return errors in either format. + let l:pattern = '^\(.* (line \(\d\+\)): \)\(.*\)$' + let l:column_pattern = '^ *\^' let l:output = [] + let l:column_offset = 0 + let l:last_line_with_message = '' - let l:i = 0 - while l:i < len(a:lines) - let l:match = matchlist(a:lines[l:i], l:pattern) - if len(l:match) && len(l:match[2]) - call add(l:output, { - \ 'col': len(a:lines[l:i + 2]), - \ 'lnum': str2nr(l:match[1]), - \ 'text': l:match[2], - \}) - endif - let l:i += 1 - endwhile + for l:line in a:lines + " Look for error lines first. + let l:match = matchlist(l:line, l:pattern) + + if !empty(l:match) + if !empty(l:last_line_with_message) + let l:text = l:last_line_with_message + else + let l:text = l:match[3] + endif + + let l:column_offset = len(l:match[1]) + + let l:last_line_with_message = '' + call add(l:output, { + \ 'col': 0, + \ 'lnum': str2nr(l:match[2]), + \ 'text': l:text, + \}) + else + " Look for column markers like ' ^' second. + " The column index will be set according to how long the line is. + let l:column_match = matchstr(l:line, l:column_pattern) + + if !empty(l:column_match) && !empty(l:output) + let l:output[-1].col = len(l:column_match) - l:column_offset + let l:last_line_with_message = '' + else + let l:last_line_with_message = l:line + let l:column_offset = 0 + endif + endif + endfor return l:output endfunction diff --git a/test/handler/test_fish_handler.vader b/test/handler/test_fish_handler.vader index 567952e4..ad3a963c 100644 --- a/test/handler/test_fish_handler.vader +++ b/test/handler/test_fish_handler.vader @@ -37,3 +37,25 @@ Execute(The fish handler should handle basic warnings and syntax errors): \ "abbr --add p 'cd ~/Projects'", \ '^', \ ]) + +Execute(The fish handler should handle problems where the problem before before the line with the line number): + AssertEqual + \ [ + \ { + \ 'lnum': 2, + \ 'col': 23, + \ 'text': 'Unsupported use of ''||''. In fish, please use ''COMMAND; or COMMAND''.', + \ }, + \ { + \ 'lnum': 5, + \ 'col': 1, + \ 'text': 'wat', + \ }, + \ ], + \ ale_linters#fish#fish#Handle(bufnr(''), [ + \ 'Unsupported use of ''||''. In fish, please use ''COMMAND; or COMMAND''.', + \ '/tmp/vLz620o/258/test.fish (line 2): if set -q SSH_CLIENT || set -q SSH_TTY', + \ ' ^', + \ '/tmp/vLz620o/258/test.fish (line 5): wat', + \ ' ^', + \ ])