#852 - Capture error codes for nimcheck

This commit is contained in:
w0rp 2017-11-19 00:38:00 +00:00
parent 3c8f3221df
commit c012563984
2 changed files with 29 additions and 20 deletions

View File

@ -10,33 +10,40 @@ function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
" Only show errors of the current buffer " Only show errors of the current buffer
" NOTE: Checking filename only is OK because nim enforces unique " NOTE: Checking filename only is OK because nim enforces unique
" module names. " module names.
let l:temp_buffer_filename = fnamemodify(l:match[1], ':p:t') let l:temp_buffer_filename = fnamemodify(l:match[1], ':p:t')
if l:buffer_filename isnot# '' && l:temp_buffer_filename isnot# l:buffer_filename if l:buffer_filename isnot# '' && l:temp_buffer_filename isnot# l:buffer_filename
continue continue
endif endif
let l:line = l:match[2] + 0 let l:item = {
let l:column = l:match[3] + 0 \ 'lnum': l:match[2] + 0,
let l:text = l:match[4] \ 'col': l:match[3] + 0,
let l:type = 'W' \ 'text': l:match[4],
\ 'type': 'W',
\}
" Extract error type from message of type 'Error: Some error message' " Extract error type from message of type 'Error: Some error message'
let l:textmatch = matchlist(l:match[4], '^\(.\{-}\): .\+$') let l:error_match = matchlist(l:item.text, '^\(.\{-}\): \(.\+\)$')
if len(l:textmatch) > 0 if !empty(l:error_match)
let l:errortype = l:textmatch[1] if l:error_match[1] is# 'Error'
if l:errortype is# 'Error' let l:item.type = 'E'
let l:type = 'E' let l:item.text = l:error_match[2]
elseif l:error_match[1] is# 'Warning'
\|| l:error_match[1] is# 'Hint'
let l:item.text = l:error_match[2]
endif endif
endif endif
call add(l:output, { let l:code_match = matchlist(l:item.text, '\v^(.+) \[([^ \[]+)\]$')
\ 'lnum': l:line,
\ 'col': l:column, if !empty(l:code_match)
\ 'text': l:text, let l:item.text = l:code_match[1]
\ 'type': l:type, let l:item.code = l:code_match[2]
\}) endif
call add(l:output, l:item)
endfor endfor
return l:output return l:output

View File

@ -12,25 +12,27 @@ Execute(Parsing nim errors should work):
\ { \ {
\ 'lnum': 8, \ 'lnum': 8,
\ 'col': 8, \ 'col': 8,
\ 'text': 'Warning: use {.base.} for base methods; baseless methods are deprecated [UseBase]', \ 'text': 'use {.base.} for base methods; baseless methods are deprecated',
\ 'code': 'UseBase',
\ 'type': 'W', \ 'type': 'W',
\ }, \ },
\ { \ {
\ 'lnum': 12, \ 'lnum': 12,
\ 'col': 2, \ 'col': 2,
\ 'text': 'Error: identifier expected, but found ''a.barfoo''', \ 'text': 'identifier expected, but found ''a.barfoo''',
\ 'type': 'E', \ 'type': 'E',
\ }, \ },
\ { \ {
\ 'lnum': 2, \ 'lnum': 2,
\ 'col': 5, \ 'col': 5,
\ 'text': 'Hint: ''NotUsed'' is declared but not used [XDeclaredButNotUsed]', \ 'text': '''NotUsed'' is declared but not used',
\ 'code': 'XDeclaredButNotUsed',
\ 'type': 'W', \ 'type': 'W',
\ }, \ },
\ { \ {
\ 'lnum': 12, \ 'lnum': 12,
\ 'col': 2, \ 'col': 2,
\ 'text': 'Error: with : character', \ 'text': 'with : character',
\ 'type': 'E', \ 'type': 'E',
\ }, \ },
\ ], \ ],