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