2017-03-18 16:33:26 +00:00
|
|
|
" Author: Baabelfish
|
|
|
|
" Description: Typechecking for nim files
|
|
|
|
|
|
|
|
function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
|
2017-03-22 09:11:32 +00:00
|
|
|
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p:t')
|
2017-03-18 16:33:26 +00:00
|
|
|
let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)'
|
2017-04-15 11:52:08 +00:00
|
|
|
let l:output = []
|
2017-03-18 16:33:26 +00:00
|
|
|
|
2017-04-17 23:35:53 +00:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-03-22 09:11:32 +00: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')
|
2017-11-19 00:38:00 +00:00
|
|
|
|
2017-08-10 23:31:42 +00:00
|
|
|
if l:buffer_filename isnot# '' && l:temp_buffer_filename isnot# l:buffer_filename
|
2017-03-22 09:11:32 +00:00
|
|
|
continue
|
|
|
|
endif
|
|
|
|
|
2017-11-19 00:38:00 +00:00
|
|
|
let l:item = {
|
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'col': l:match[3] + 0,
|
|
|
|
\ 'text': l:match[4],
|
|
|
|
\ 'type': 'W',
|
|
|
|
\}
|
2017-03-18 16:33:26 +00:00
|
|
|
|
2017-03-22 09:11:32 +00:00
|
|
|
" Extract error type from message of type 'Error: Some error message'
|
2017-11-19 00:38:00 +00:00
|
|
|
let l:error_match = matchlist(l:item.text, '^\(.\{-}\): \(.\+\)$')
|
2017-03-18 16:33:26 +00:00
|
|
|
|
2017-11-19 00:38:00 +00:00
|
|
|
if !empty(l:error_match)
|
|
|
|
if l:error_match[1] is# 'Error'
|
|
|
|
let l:item.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]
|
2017-03-18 16:33:26 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2017-11-19 00:38:00 +00:00
|
|
|
let l:code_match = matchlist(l:item.text, '\v^(.+) \[([^ \[]+)\]$')
|
|
|
|
|
|
|
|
if !empty(l:code_match)
|
|
|
|
let l:item.text = l:code_match[1]
|
|
|
|
let l:item.code = l:code_match[2]
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(l:output, l:item)
|
2017-03-18 16:33:26 +00:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2017-04-15 11:52:08 +00:00
|
|
|
function! ale_linters#nim#nimcheck#GetCommand(buffer) abort
|
2017-06-06 08:55:19 +00:00
|
|
|
return 'nim check --verbosity:0 --colors:off --listFullPaths %s'
|
2017-03-18 16:33:26 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
|
|
call ale#linter#Define('nim', {
|
|
|
|
\ 'name': 'nimcheck',
|
|
|
|
\ 'executable': 'nim',
|
|
|
|
\ 'output_stream': 'both',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'command': function('ale_linters#nim#nimcheck#GetCommand'),
|
2017-06-06 08:55:19 +00:00
|
|
|
\ 'callback': 'ale_linters#nim#nimcheck#Handle',
|
|
|
|
\ 'lint_file': 1,
|
2017-03-18 16:33:26 +00:00
|
|
|
\})
|