#2132 - Implement deferred command handling for linters

This commit is contained in:
w0rp
2019-02-21 21:24:41 +00:00
parent a8b987a1c3
commit ffa45fa3fb
9 changed files with 102 additions and 11 deletions

View File

@@ -59,13 +59,18 @@ function! ale#assert#Linter(expected_executable, expected_command) abort
endif
else
let l:command = ale#linter#GetCommand(l:buffer, l:linter)
while ale#command#IsDeferred(l:command)
call ale#test#FlushJobs()
let l:command = l:command.value
endwhile
endif
if type(l:command) is v:t_string
" Replace %e with the escaped executable, so tests keep passing after
" linters are changed to use %e.
let l:command = substitute(l:command, '%e', '\=ale#Escape(l:executable)', 'g')
else
elseif type(l:command) is v:t_list
call map(l:command, 'substitute(v:val, ''%e'', ''\=ale#Escape(l:executable)'', ''g'')')
endif

View File

@@ -320,6 +320,10 @@ function! ale#command#Run(buffer, command, Callback, ...) abort
call ale#history#Add(a:buffer, l:status, l:job_id, l:command)
endif
if !l:job_id
return 0
endif
" We'll return this Dictionary. A `result_callback` can be assigned to it
" later for capturing the result of a:Callback.
"

View File

@@ -422,8 +422,16 @@ endfunction
" Run a job.
"
" Returns 1 when the job was started successfully.
" Returns 1 when a job was started successfully.
function! s:RunJob(command, options) abort
if ale#command#IsDeferred(a:command)
let a:command.result_callback = {
\ command -> s:RunJob(command, a:options)
\}
return 1
endif
let l:command = a:command
if empty(l:command)
@@ -451,7 +459,7 @@ function! s:RunJob(command, options) abort
\})
" Only proceed if the job is being run.
if !l:result._deferred_job_id
if empty(l:result)
return 0
endif

View File

@@ -179,7 +179,7 @@ function! s:RunJob(options) abort
\ 'log_output': 0,
\})
return l:result._deferred_job_id != 0
return !empty(l:result)
endfunction
function! s:RunFixer(options) abort

View File

@@ -177,7 +177,8 @@ function! ale#linter#PreProcess(filetype, linter) abort
let l:obj.command = a:linter.command
if type(l:obj.command) isnot v:t_string
throw '`command` must be a string if defined'
\&& type(l:obj.command) isnot v:t_func
throw '`command` must be a String or Function if defined'
endif
else
throw 'Either `command`, `executable_callback`, `command_chain` '
@@ -489,9 +490,13 @@ endfunction
" Given a buffer and linter, get the command String for the linter.
" The command_chain key is not supported.
function! ale#linter#GetCommand(buffer, linter) abort
return has_key(a:linter, 'command_callback')
\ ? ale#util#GetFunction(a:linter.command_callback)(a:buffer)
let l:Command = has_key(a:linter, 'command_callback')
\ ? function(a:linter.command_callback)
\ : a:linter.command
return type(l:Command) is v:t_func
\ ? l:Command(a:buffer)
\ : l:Command
endfunction
" Given a buffer and linter, get the address for connecting to the server.