diff options
author | w0rp <devw0rp@gmail.com> | 2016-09-11 16:49:55 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2016-09-11 16:49:55 +0100 |
commit | 4dcfdd43e11b1b000d4e27444cf2c0dbd3f22111 (patch) | |
tree | 6f7092f9e6171aa4af12ac8cafa657c04a125fc5 | |
parent | 899e0278591a717f961728be9b18fa1919cd4926 (diff) | |
download | ale-4dcfdd43e11b1b000d4e27444cf2c0dbd3f22111.zip |
Add support for defining linters where the command that is run is determined by a callback.
-rw-r--r-- | plugin/ale/zmain.vim | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/plugin/ale/zmain.vim b/plugin/ale/zmain.vim index 994422f2..abfc4afc 100644 --- a/plugin/ale/zmain.vim +++ b/plugin/ale/zmain.vim @@ -13,6 +13,14 @@ let s:linters = {} let s:job_linter_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) let linter = s:job_linter_map[a:job] @@ -73,7 +81,7 @@ function! s:HandleExit(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 let b:ale_should_reset_loclist = 0 @@ -114,20 +122,29 @@ function! s:ApplyLinter(linter) call s:ClearJob(a:linter.job) 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') - let a:linter.job = jobstart(a:linter.command, { + let a:linter.job = jobstart(command, { \ 'on_stdout': 's:GatherOutputNeoVim', \ 'on_exit': 's:HandleExitNeoVim', \}) else " 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', \ 'err_mode': 'nl', \ 'out_cb': function('s:GatherOutputVim'), \ 'close_cb': function('s:HandleExitVim'), \ 'in_io': 'buffer', - \ 'in_buf': bufnr('%'), + \ 'in_buf': buffer, \}) call ch_close_in(job_getchannel(a:linter.job)) @@ -165,10 +182,15 @@ function! ALEAddLinter(filetype, linter) let s:linters[a:filetype] = [] endif - call add(s:linters[a:filetype], { - \ 'command': a:linter.command, - \ 'callback': a:linter.callback, - \}) + let new_linter = {'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 function! ALEGetLinters(filetype) |