diff options
author | w0rp <devw0rp@gmail.com> | 2016-09-15 20:20:41 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2016-09-15 20:20:41 +0100 |
commit | 8cc28cdfbd34dd76bd1cd392747c266be7833494 (patch) | |
tree | c136f8753293246f8d837607268250eab41c8820 /plugin | |
parent | d3047c9cf643cb80418b394c6cf16bc9dcec916d (diff) | |
download | ale-8cc28cdfbd34dd76bd1cd392747c266be7833494.zip |
Add support for Bash and other shells. Add support for reading from stderr, and for generating the executable from functions. Both were needed to support shell linting.
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/ale/zmain.vim | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/plugin/ale/zmain.vim b/plugin/ale/zmain.vim index 548ae290..5547f695 100644 --- a/plugin/ale/zmain.vim +++ b/plugin/ale/zmain.vim @@ -141,20 +141,36 @@ function! s:ApplyLinter(buffer, linter) endif if has('nvim') - let a:linter.job = jobstart(command, { - \ 'on_stdout': 's:GatherOutputNeoVim', - \ 'on_exit': 's:HandleExitNeoVim', - \}) + if a:linter.output_stream ==# 'stderr' + " Read from stderr instead of stdout. + let a:linter.job = jobstart(command, { + \ 'on_stderr': 's:GatherOutputNeoVim', + \ 'on_exit': 's:HandleExitNeoVim', + \}) + else + let a:linter.job = jobstart(command, { + \ 'on_stdout': 's:GatherOutputNeoVim', + \ 'on_exit': 's:HandleExitNeoVim', + \}) + endif else - " Vim 8 will read the stdin from the file's buffer. - let a:linter.job = job_start(command, { + let job_options = { \ 'out_mode': 'nl', \ 'err_mode': 'nl', - \ 'out_cb': function('s:GatherOutputVim'), \ 'close_cb': function('s:HandleExitVim'), \ 'in_io': 'buffer', \ 'in_buf': a:buffer, - \}) + \} + + if a:linter.output_stream ==# 'stderr' + " Read from stderr instead of stdout. + let job_options.err_cb = function('s:GatherOutputVim') + else + let job_options.out_cb = function('s:GatherOutputVim') + endif + + " Vim 8 will read the stdin from the file's buffer. + let a:linter.job = job_start(l:command, l:job_options) call ch_close_in(job_getchannel(a:linter.job)) endif @@ -182,6 +198,18 @@ function! s:TimerHandler(...) let g:ale_buffer_should_reset_map[buffer] = 1 for linter in linters + " Check if a given linter has a program which can be executed. + if has_key(linter, 'executable_callback') + let l:executable = s:GetFunction(linter.executable_callback)(buffer) + else + let l:executable = linter.executable + endif + + if !executable(l:executable) + " The linter's program cannot be executed, so skip it. + continue + endif + call s:ApplyLinter(buffer, linter) endfor endfunction @@ -197,16 +225,20 @@ function s:BufferCleanup(buffer) endfunction function! ALEAddLinter(filetype, linter) - " Check if the linter program is executable before adding it. - if !executable(a:linter.executable) - return - endif - if !has_key(s:linters, a:filetype) let s:linters[a:filetype] = [] endif - let new_linter = {'callback': a:linter.callback} + let new_linter = { + \ 'name': a:linter.name, + \ 'callback': a:linter.callback, + \} + + if has_key(a:linter, 'executable_callback') + let new_linter.executable_callback = a:linter.executable_callback + else + let new_linter.executable = a:linter.executable + endif if has_key(a:linter, 'command_callback') let new_linter.command_callback = a:linter.command_callback @@ -214,6 +246,14 @@ function! ALEAddLinter(filetype, linter) let new_linter.command = a:linter.command endif + if has_key(a:linter, 'output_stream') + let new_linter.output_stream = a:linter.output_stream + else + let new_linter.output_stream = 'stdout' + endif + + " TODO: Assert the value of the output_stream to be something sensible. + call add(s:linters[a:filetype], new_linter) endfunction |