Fix #1373 - Fix a bug with Fish errors not being handled on Linux

This commit is contained in:
w0rp 2018-03-23 12:17:49 +00:00
parent ec5750f57b
commit dbf530e87f
2 changed files with 67 additions and 14 deletions

View File

@ -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 " home/.config/fish/functions/foo.fish (line 1): Missing end to balance this function definition
" function foo " function foo
" ^ " ^
" <W> 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:output = []
let l:column_offset = 0
let l:last_line_with_message = ''
let l:i = 0 for l:line in a:lines
while l:i < len(a:lines) " Look for error lines first.
let l:match = matchlist(a:lines[l:i], l:pattern) let l:match = matchlist(l:line, l:pattern)
if len(l:match) && len(l:match[2])
call add(l:output, { if !empty(l:match)
\ 'col': len(a:lines[l:i + 2]), if !empty(l:last_line_with_message)
\ 'lnum': str2nr(l:match[1]), let l:text = l:last_line_with_message
\ 'text': l:match[2], else
\}) let l:text = l:match[3]
endif endif
let l:i += 1
endwhile 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 return l:output
endfunction endfunction

View File

@ -37,3 +37,25 @@ Execute(The fish handler should handle basic warnings and syntax errors):
\ "abbr --add p 'cd ~/Projects'", \ "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',
\ ' ^',
\ ])