2017-03-18 12:33:26 -04:00
|
|
|
" Author: Baabelfish
|
|
|
|
" Description: Typechecking for nim files
|
|
|
|
|
|
|
|
function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
|
2017-03-22 05:11:32 -04:00
|
|
|
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p:t')
|
2017-03-18 12:33:26 -04:00
|
|
|
let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)'
|
2017-04-15 07:52:08 -04:00
|
|
|
let l:output = []
|
2017-03-18 12:33:26 -04:00
|
|
|
|
2017-04-17 19:35:53 -04:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-03-22 05:11:32 -04:00
|
|
|
" Only show errors of the current buffer
|
|
|
|
" NOTE: Checking filename only is OK because nim enforces unique
|
|
|
|
" module names.
|
|
|
|
|
|
|
|
let l:temp_buffer_filename = fnamemodify(l:match[1], ':p:t')
|
|
|
|
if l:buffer_filename !=# '' && l:temp_buffer_filename !=# l:buffer_filename
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2017-03-18 12:33:26 -04:00
|
|
|
let l:line = l:match[2] + 0
|
|
|
|
let l:column = l:match[3] + 0
|
|
|
|
let l:text = l:match[4]
|
|
|
|
let l:type = 'W'
|
|
|
|
|
2017-03-22 05:11:32 -04:00
|
|
|
" Extract error type from message of type 'Error: Some error message'
|
|
|
|
let l:textmatch = matchlist(l:match[4], '^\(.\{-}\): .\+$')
|
2017-03-18 12:33:26 -04:00
|
|
|
|
|
|
|
if len(l:textmatch) > 0
|
|
|
|
let l:errortype = l:textmatch[1]
|
|
|
|
if l:errortype ==# 'Error'
|
|
|
|
let l:type = 'E'
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:line,
|
|
|
|
\ 'col': l:column,
|
|
|
|
\ 'text': l:text,
|
|
|
|
\ 'type': l:type,
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-04-15 07:52:08 -04:00
|
|
|
function! ale_linters#nim#nimcheck#GetCommand(buffer) abort
|
2017-05-08 17:59:25 -04:00
|
|
|
let l:directory = shellescape(fnamemodify(bufname(a:buffer), ':p:h'))
|
2017-04-15 08:35:54 -04:00
|
|
|
|
|
|
|
return 'nim check --path:' . l:directory
|
|
|
|
\ . ' --threads:on --verbosity:0 --colors:off --listFullPaths %t'
|
2017-03-18 12:33:26 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
call ale#linter#Define('nim', {
|
|
|
|
\ 'name': 'nimcheck',
|
|
|
|
\ 'executable': 'nim',
|
|
|
|
\ 'output_stream': 'both',
|
|
|
|
\ 'command_callback': 'ale_linters#nim#nimcheck#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#nim#nimcheck#Handle'
|
|
|
|
\})
|