2017-04-13 05:25:35 -04:00
|
|
|
" Author: Ben Reedy <https://github.com/breed808>
|
|
|
|
" Description: Adds support for the gometalinter suite for Go files
|
|
|
|
|
2017-07-06 19:10:30 -04:00
|
|
|
call ale#Set('go_gometalinter_options', '')
|
|
|
|
call ale#Set('go_gometalinter_executable', 'gometalinter')
|
|
|
|
|
|
|
|
function! ale_linters#go#gometalinter#GetExecutable(buffer) abort
|
|
|
|
return ale#Var(a:buffer, 'go_gometalinter_executable')
|
|
|
|
endfunction
|
2017-04-13 05:25:35 -04:00
|
|
|
|
|
|
|
function! ale_linters#go#gometalinter#GetCommand(buffer) abort
|
2017-07-06 19:10:30 -04:00
|
|
|
let l:executable = ale_linters#go#gometalinter#GetExecutable(a:buffer)
|
2017-07-11 10:52:18 -04:00
|
|
|
let l:filename = expand('#' . a:buffer)
|
2017-07-06 19:10:30 -04:00
|
|
|
let l:options = ale#Var(a:buffer, 'go_gometalinter_options')
|
2017-06-06 05:22:52 -04:00
|
|
|
|
2017-07-06 19:10:30 -04:00
|
|
|
return ale#Escape(l:executable)
|
2017-07-11 18:47:13 -04:00
|
|
|
\ . ' --include=' . ale#Escape(ale#util#EscapePCRE(l:filename))
|
2017-07-06 19:10:30 -04:00
|
|
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
|
|
|
\ . ' ' . ale#Escape(fnamemodify(l:filename, ':h'))
|
2017-04-13 05:25:35 -04:00
|
|
|
endfunction
|
|
|
|
|
2017-04-29 12:33:18 -04:00
|
|
|
function! ale_linters#go#gometalinter#GetMatches(lines) abort
|
|
|
|
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):?(\d+)?:?:?(warning|error):?\s\*?(.+)$'
|
|
|
|
|
|
|
|
return ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
endfunction
|
|
|
|
|
2017-04-13 05:25:35 -04:00
|
|
|
function! ale_linters#go#gometalinter#Handler(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
2017-04-29 12:33:18 -04:00
|
|
|
for l:match in ale_linters#go#gometalinter#GetMatches(a:lines)
|
2017-04-13 05:25:35 -04:00
|
|
|
call add(l:output, {
|
2017-04-29 12:33:18 -04:00
|
|
|
\ 'lnum': l:match[2] + 0,
|
|
|
|
\ 'col': l:match[3] + 0,
|
|
|
|
\ 'type': tolower(l:match[4]) ==# 'warning' ? 'W' : 'E',
|
|
|
|
\ 'text': l:match[5],
|
2017-04-13 05:25:35 -04:00
|
|
|
\})
|
|
|
|
endfor
|
2017-04-15 16:04:43 -04:00
|
|
|
|
2017-04-13 05:25:35 -04:00
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('go', {
|
|
|
|
\ 'name': 'gometalinter',
|
2017-07-06 19:10:30 -04:00
|
|
|
\ 'executable_callback': 'ale_linters#go#gometalinter#GetExecutable',
|
2017-04-13 05:25:35 -04:00
|
|
|
\ 'command_callback': 'ale_linters#go#gometalinter#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#go#gometalinter#Handler',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|