summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-02-21 21:24:41 +0000
committerw0rp <devw0rp@gmail.com>2019-02-21 21:24:41 +0000
commitffa45fa3fb44ade28c64aa8f0a21acd71c903a2a (patch)
tree350f4b45b17a1862844a14856c4063c0d219f0bd /autoload
parenta8b987a1c31f297622f0038230d23404e7c2ad50 (diff)
downloadale-ffa45fa3fb44ade28c64aa8f0a21acd71c903a2a.zip
#2132 - Implement deferred command handling for linters
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/assert.vim7
-rw-r--r--autoload/ale/command.vim4
-rw-r--r--autoload/ale/engine.vim12
-rw-r--r--autoload/ale/fix.vim2
-rw-r--r--autoload/ale/linter.vim11
5 files changed, 29 insertions, 7 deletions
diff --git a/autoload/ale/assert.vim b/autoload/ale/assert.vim
index ef2dab9e..1b004649 100644
--- a/autoload/ale/assert.vim
+++ b/autoload/ale/assert.vim
@@ -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
diff --git a/autoload/ale/command.vim b/autoload/ale/command.vim
index 7a66dc77..33ce577c 100644
--- a/autoload/ale/command.vim
+++ b/autoload/ale/command.vim
@@ -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.
"
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index b4035422..340f6913 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -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
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim
index 7c428f52..48874a8a 100644
--- a/autoload/ale/fix.vim
+++ b/autoload/ale/fix.vim
@@ -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
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index 86ee506c..8c9f83ad 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -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.