Add support for defining linters where the command that is run is determined by a callback.
This commit is contained in:
parent
899e027859
commit
4dcfdd43e1
@ -13,6 +13,14 @@ let s:linters = {}
|
|||||||
let s:job_linter_map = {}
|
let s:job_linter_map = {}
|
||||||
let s:job_output_map = {}
|
let s:job_output_map = {}
|
||||||
|
|
||||||
|
function! s:GetFunction(string_or_ref)
|
||||||
|
if type(a:string_or_ref) == type('')
|
||||||
|
return function(a:string_or_ref)
|
||||||
|
endif
|
||||||
|
|
||||||
|
return a:string_or_ref
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:ClearJob(job)
|
function! s:ClearJob(job)
|
||||||
let linter = s:job_linter_map[a:job]
|
let linter = s:job_linter_map[a:job]
|
||||||
|
|
||||||
@ -73,7 +81,7 @@ function! s:HandleExit(job)
|
|||||||
|
|
||||||
call s:ClearJob(a:job)
|
call s:ClearJob(a:job)
|
||||||
|
|
||||||
let linter_loclist = function(linter.callback)(output)
|
let linter_loclist = s:GetFunction(linter.callback)(output)
|
||||||
|
|
||||||
if b:ale_should_reset_loclist
|
if b:ale_should_reset_loclist
|
||||||
let b:ale_should_reset_loclist = 0
|
let b:ale_should_reset_loclist = 0
|
||||||
@ -114,20 +122,29 @@ function! s:ApplyLinter(linter)
|
|||||||
call s:ClearJob(a:linter.job)
|
call s:ClearJob(a:linter.job)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let buffer = bufnr('%')
|
||||||
|
|
||||||
|
if has_key(a:linter, 'command_callback')
|
||||||
|
" If there is a callback for generating a command, call that instead.
|
||||||
|
let command = s:GetFunction(a:linter.command_callback)(buffer)
|
||||||
|
else
|
||||||
|
let command = a:linter.command
|
||||||
|
endif
|
||||||
|
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
let a:linter.job = jobstart(a:linter.command, {
|
let a:linter.job = jobstart(command, {
|
||||||
\ 'on_stdout': 's:GatherOutputNeoVim',
|
\ 'on_stdout': 's:GatherOutputNeoVim',
|
||||||
\ 'on_exit': 's:HandleExitNeoVim',
|
\ 'on_exit': 's:HandleExitNeoVim',
|
||||||
\})
|
\})
|
||||||
else
|
else
|
||||||
" Vim 8 will read the stdin from the file's buffer.
|
" Vim 8 will read the stdin from the file's buffer.
|
||||||
let a:linter.job = job_start(a:linter.command, {
|
let a:linter.job = job_start(command, {
|
||||||
\ 'out_mode': 'nl',
|
\ 'out_mode': 'nl',
|
||||||
\ 'err_mode': 'nl',
|
\ 'err_mode': 'nl',
|
||||||
\ 'out_cb': function('s:GatherOutputVim'),
|
\ 'out_cb': function('s:GatherOutputVim'),
|
||||||
\ 'close_cb': function('s:HandleExitVim'),
|
\ 'close_cb': function('s:HandleExitVim'),
|
||||||
\ 'in_io': 'buffer',
|
\ 'in_io': 'buffer',
|
||||||
\ 'in_buf': bufnr('%'),
|
\ 'in_buf': buffer,
|
||||||
\})
|
\})
|
||||||
|
|
||||||
call ch_close_in(job_getchannel(a:linter.job))
|
call ch_close_in(job_getchannel(a:linter.job))
|
||||||
@ -165,10 +182,15 @@ function! ALEAddLinter(filetype, linter)
|
|||||||
let s:linters[a:filetype] = []
|
let s:linters[a:filetype] = []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call add(s:linters[a:filetype], {
|
let new_linter = {'callback': a:linter.callback}
|
||||||
\ 'command': a:linter.command,
|
|
||||||
\ 'callback': a:linter.callback,
|
if has_key(a:linter, 'command_callback')
|
||||||
\})
|
let new_linter.command_callback = a:linter.command_callback
|
||||||
|
else
|
||||||
|
let new_linter.command = a:linter.command
|
||||||
|
endif
|
||||||
|
|
||||||
|
call add(s:linters[a:filetype], new_linter)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ALEGetLinters(filetype)
|
function! ALEGetLinters(filetype)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user