Disable piping buffer data into commands for fixing files where needed

This commit is contained in:
w0rp 2017-11-22 13:01:13 +00:00
parent e7865d2f94
commit 3f70f1cbf1
3 changed files with 49 additions and 2 deletions

View File

@ -185,6 +185,7 @@ function! s:RunJob(options) abort
let l:output_stream = a:options.output_stream let l:output_stream = a:options.output_stream
let l:read_temporary_file = a:options.read_temporary_file let l:read_temporary_file = a:options.read_temporary_file
let l:chain_with = a:options.chain_with let l:chain_with = a:options.chain_with
let l:read_buffer = a:options.read_buffer
if empty(l:command) if empty(l:command)
" If there's nothing further to chain the command with, stop here. " If there's nothing further to chain the command with, stop here.
@ -205,7 +206,11 @@ function! s:RunJob(options) abort
return 1 return 1
endif endif
let [l:temporary_file, l:command] = ale#command#FormatCommand(l:buffer, l:command, 1) let [l:temporary_file, l:command] = ale#command#FormatCommand(
\ l:buffer,
\ l:command,
\ l:read_buffer,
\)
call s:CreateTemporaryFileForJob(l:buffer, l:temporary_file, l:input) call s:CreateTemporaryFileForJob(l:buffer, l:temporary_file, l:input)
let l:command = ale#job#PrepareCommand(l:command) let l:command = ale#job#PrepareCommand(l:command)
@ -309,13 +314,19 @@ function! s:RunFixer(options) abort
let l:input = l:result let l:input = l:result
let l:index += 1 let l:index += 1
else else
" Capitals are required for funcrefs.
let l:Chain_with = get(l:result, 'chain_with', v:null)
" Default to piping the buffer for the last fixer in the chain.
let l:read_buffer = get(l:result, 'read_buffer', l:Chain_with is v:null)
let l:job_ran = s:RunJob({ let l:job_ran = s:RunJob({
\ 'buffer': l:buffer, \ 'buffer': l:buffer,
\ 'command': l:result.command, \ 'command': l:result.command,
\ 'input': l:input, \ 'input': l:input,
\ 'output_stream': get(l:result, 'output_stream', 'stdout'), \ 'output_stream': get(l:result, 'output_stream', 'stdout'),
\ 'read_temporary_file': get(l:result, 'read_temporary_file', 0), \ 'read_temporary_file': get(l:result, 'read_temporary_file', 0),
\ 'chain_with': get(l:result, 'chain_with', v:null), \ 'read_buffer': l:read_buffer,
\ 'chain_with': l:Chain_with,
\ 'callback_list': a:options.callback_list, \ 'callback_list': a:options.callback_list,
\ 'callback_index': l:index, \ 'callback_index': l:index,
\}) \})

View File

@ -479,6 +479,18 @@ are supported for running the commands.
that are cached. An empty List will be passed to the that are cached. An empty List will be passed to the
next callback in the chain for the `output`. next callback in the chain for the `output`.
`read_buffer` An optional key for disabling reading the buffer.
When set to `0`, ALE will not pipe the buffer's data
into the command via stdin. This option is ignored and
the buffer is not read when `read_temporary_file` is
`1`.
This option defaults to `0` when `chain_with` is defined
as anything other than `v:null`, and defaults to `1`
otherwise. This is so earlier commands in a chain
do not receive the buffer's data by default.
*ale-fix-configuration* *ale-fix-configuration*
Synchronous functions and asynchronous jobs will be run in a sequence for Synchronous functions and asynchronous jobs will be run in a sequence for

View File

@ -110,6 +110,10 @@ Before:
return {'command': has('win32') ? 'echo(' : 'echo'} return {'command': has('win32') ? 'echo(' : 'echo'}
endfunction endfunction
function! EchoLineNoPipe(buffer, output)
return {'command': 'echo new line', 'read_buffer': 0}
endfunction
function! SetUpLinters() function! SetUpLinters()
call ale#linter#Define('testft', { call ale#linter#Define('testft', {
\ 'name': 'testlinter', \ 'name': 'testlinter',
@ -155,6 +159,7 @@ After:
delfunction SetUpLinters delfunction SetUpLinters
delfunction GetLastMessage delfunction GetLastMessage
delfunction IgnoredEmptyOutput delfunction IgnoredEmptyOutput
delfunction EchoLineNoPipe
call ale#test#RestoreDirectory() call ale#test#RestoreDirectory()
@ -540,6 +545,14 @@ Execute(Test fixing with chained callbacks):
let g:ale_fixers.testft = ['FirstChainCallback'] let g:ale_fixers.testft = ['FirstChainCallback']
ALEFix ALEFix
" The buffer shouldn't be piped in for earlier commands in the chain.
AssertEqual
\ [
\ string(ale#job#PrepareCommand('echo echoline')),
\ string(ale#job#PrepareCommand('echo echoline')),
\ ],
\ map(ale#history#Get(bufnr(''))[-2:-1], 'string(v:val.command)')
Expect(The echoed line should be added): Expect(The echoed line should be added):
a a
b b
@ -583,3 +596,14 @@ Expect(The lines should be the same):
a a
b b
c c
Execute(A temporary file shouldn't be piped into the command when disabled):
let g:ale_fixers.testft = ['EchoLineNoPipe']
ALEFix
AssertEqual
\ string(ale#job#PrepareCommand('echo new line')),
\ string(ale#history#Get(bufnr(''))[-1].command)
Expect(The new line should be used):
new line