Updated plugins
This commit is contained in:
1 parent
1d42b63013
commit
f50b2142bc
356 files changed
+6183
-3837
No files matched your search
@@ -5,20 +5,10 @@
|
||||
" Remapping of linter problems.
|
||||
let g:ale_type_map = get(g:, 'ale_type_map', {})
|
||||
|
||||
" Stores information for each job including:
|
||||
"
|
||||
" linter: The linter dictionary for the job.
|
||||
" buffer: The buffer number for the job.
|
||||
" output: The array of lines for the output of the job.
|
||||
if !has_key(s:, 'job_info_map')
|
||||
let s:job_info_map = {}
|
||||
endif
|
||||
|
||||
if !has_key(s:, 'executable_cache_map')
|
||||
let s:executable_cache_map = {}
|
||||
endif
|
||||
|
||||
|
||||
function! ale#engine#CleanupEveryBuffer() abort
|
||||
for l:key in keys(g:ale_buffer_info)
|
||||
" The key could be a filename or a buffer number, so try and
|
||||
@@ -34,6 +24,25 @@ function! ale#engine#CleanupEveryBuffer() abort
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! ale#engine#MarkLinterActive(info, linter) abort
|
||||
let l:found = 0
|
||||
|
||||
for l:other_linter in a:info.active_linter_list
|
||||
if l:other_linter.name is# a:linter.name
|
||||
let l:found = 1
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
if !l:found
|
||||
call add(a:info.active_linter_list, a:linter)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#engine#MarkLinterInactive(info, linter) abort
|
||||
call filter(a:info.active_linter_list, 'v:val.name isnot# a:linter.name')
|
||||
endfunction
|
||||
|
||||
function! ale#engine#ResetExecutableCache() abort
|
||||
let s:executable_cache_map = {}
|
||||
endfunction
|
||||
@@ -71,18 +80,12 @@ endfunction
|
||||
|
||||
function! ale#engine#InitBufferInfo(buffer) abort
|
||||
if !has_key(g:ale_buffer_info, a:buffer)
|
||||
" job_list will hold the list of job IDs
|
||||
" active_linter_list will hold the list of active linter names
|
||||
" loclist holds the loclist items after all jobs have completed.
|
||||
" temporary_file_list holds temporary files to be cleaned up
|
||||
" temporary_directory_list holds temporary directories to be cleaned up
|
||||
let g:ale_buffer_info[a:buffer] = {
|
||||
\ 'job_list': [],
|
||||
\ 'active_linter_list': [],
|
||||
\ 'active_other_sources_list': [],
|
||||
\ 'loclist': [],
|
||||
\ 'temporary_file_list': [],
|
||||
\ 'temporary_directory_list': [],
|
||||
\}
|
||||
|
||||
return 1
|
||||
@@ -104,79 +107,25 @@ endfunction
|
||||
" Register a temporary file to be managed with the ALE engine for
|
||||
" a current job run.
|
||||
function! ale#engine#ManageFile(buffer, filename) abort
|
||||
call ale#engine#InitBufferInfo(a:buffer)
|
||||
call add(g:ale_buffer_info[a:buffer].temporary_file_list, a:filename)
|
||||
" TODO: Emit deprecation warning here later.
|
||||
call ale#command#ManageFile(a:buffer, a:filename)
|
||||
endfunction
|
||||
|
||||
" Same as the above, but manage an entire directory.
|
||||
function! ale#engine#ManageDirectory(buffer, directory) abort
|
||||
call ale#engine#InitBufferInfo(a:buffer)
|
||||
call add(g:ale_buffer_info[a:buffer].temporary_directory_list, a:directory)
|
||||
" TODO: Emit deprecation warning here later.
|
||||
call ale#command#ManageDirectory(a:buffer, a:directory)
|
||||
endfunction
|
||||
|
||||
function! ale#engine#CreateFile(buffer) abort
|
||||
" This variable can be set to 1 in tests to stub this out.
|
||||
if get(g:, 'ale_create_dummy_temporary_file')
|
||||
return 'TEMP'
|
||||
endif
|
||||
|
||||
let l:temporary_file = ale#util#Tempname()
|
||||
call ale#engine#ManageFile(a:buffer, l:temporary_file)
|
||||
|
||||
return l:temporary_file
|
||||
" TODO: Emit deprecation warning here later.
|
||||
return ale#command#CreateFile(a:buffer)
|
||||
endfunction
|
||||
|
||||
" Create a new temporary directory and manage it in one go.
|
||||
function! ale#engine#CreateDirectory(buffer) abort
|
||||
" This variable can be set to 1 in tests to stub this out.
|
||||
if get(g:, 'ale_create_dummy_temporary_file')
|
||||
return 'TEMP_DIR'
|
||||
endif
|
||||
|
||||
let l:temporary_directory = ale#util#Tempname()
|
||||
" Create the temporary directory for the file, unreadable by 'other'
|
||||
" users.
|
||||
call mkdir(l:temporary_directory, '', 0750)
|
||||
call ale#engine#ManageDirectory(a:buffer, l:temporary_directory)
|
||||
|
||||
return l:temporary_directory
|
||||
endfunction
|
||||
|
||||
function! ale#engine#RemoveManagedFiles(buffer) abort
|
||||
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||
|
||||
" We can't delete anything in a sandbox, so wait until we escape from
|
||||
" it to delete temporary files and directories.
|
||||
if ale#util#InSandbox()
|
||||
return
|
||||
endif
|
||||
|
||||
" Delete files with a call akin to a plan `rm` command.
|
||||
if has_key(l:info, 'temporary_file_list')
|
||||
for l:filename in l:info.temporary_file_list
|
||||
call delete(l:filename)
|
||||
endfor
|
||||
|
||||
let l:info.temporary_file_list = []
|
||||
endif
|
||||
|
||||
" Delete directories like `rm -rf`.
|
||||
" Directories are handled differently from files, so paths that are
|
||||
" intended to be single files can be set up for automatic deletion without
|
||||
" accidentally deleting entire directories.
|
||||
if has_key(l:info, 'temporary_directory_list')
|
||||
for l:directory in l:info.temporary_directory_list
|
||||
call delete(l:directory, 'rf')
|
||||
endfor
|
||||
|
||||
let l:info.temporary_directory_list = []
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GatherOutput(job_id, line) abort
|
||||
if has_key(s:job_info_map, a:job_id)
|
||||
call add(s:job_info_map[a:job_id].output, a:line)
|
||||
endif
|
||||
" TODO: Emit deprecation warning here later.
|
||||
return ale#command#CreateDirectory(a:buffer)
|
||||
endfunction
|
||||
|
||||
function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_source) abort
|
||||
@@ -189,7 +138,7 @@ function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_sour
|
||||
if !a:from_other_source
|
||||
" Remove this linter from the list of active linters.
|
||||
" This may have already been done when the job exits.
|
||||
call filter(l:info.active_linter_list, 'v:val isnot# a:linter_name')
|
||||
call filter(l:info.active_linter_list, 'v:val.name isnot# a:linter_name')
|
||||
endif
|
||||
|
||||
" Make some adjustments to the loclists to fix common problems, and also
|
||||
@@ -222,27 +171,19 @@ function! ale#engine#HandleLoclist(linter_name, buffer, loclist, from_other_sour
|
||||
call ale#engine#SetResults(a:buffer, l:info.loclist)
|
||||
endfunction
|
||||
|
||||
function! s:HandleExit(job_id, exit_code) abort
|
||||
if !has_key(s:job_info_map, a:job_id)
|
||||
function! s:HandleExit(job_info, buffer, output, data) abort
|
||||
let l:buffer_info = get(g:ale_buffer_info, a:buffer)
|
||||
|
||||
if empty(l:buffer_info)
|
||||
return
|
||||
endif
|
||||
|
||||
let l:job_info = s:job_info_map[a:job_id]
|
||||
let l:linter = l:job_info.linter
|
||||
let l:output = l:job_info.output
|
||||
let l:buffer = l:job_info.buffer
|
||||
let l:executable = l:job_info.executable
|
||||
let l:next_chain_index = l:job_info.next_chain_index
|
||||
|
||||
if g:ale_history_enabled
|
||||
call ale#history#SetExitCode(l:buffer, a:job_id, a:exit_code)
|
||||
endif
|
||||
let l:linter = a:job_info.linter
|
||||
let l:executable = a:job_info.executable
|
||||
let l:next_chain_index = a:job_info.next_chain_index
|
||||
|
||||
" Remove this job from the list.
|
||||
call ale#job#Stop(a:job_id)
|
||||
call remove(s:job_info_map, a:job_id)
|
||||
call filter(g:ale_buffer_info[l:buffer].job_list, 'v:val isnot# a:job_id')
|
||||
call filter(g:ale_buffer_info[l:buffer].active_linter_list, 'v:val isnot# l:linter.name')
|
||||
call ale#engine#MarkLinterInactive(l:buffer_info, l:linter)
|
||||
|
||||
" Stop here if we land in the handle for a job completing if we're in
|
||||
" a sandbox.
|
||||
@@ -250,29 +191,32 @@ function! s:HandleExit(job_id, exit_code) abort
|
||||
return
|
||||
endif
|
||||
|
||||
if has('nvim') && !empty(l:output) && empty(l:output[-1])
|
||||
call remove(l:output, -1)
|
||||
if has('nvim') && !empty(a:output) && empty(a:output[-1])
|
||||
call remove(a:output, -1)
|
||||
endif
|
||||
|
||||
if l:next_chain_index < len(get(l:linter, 'command_chain', []))
|
||||
call s:InvokeChain(l:buffer, l:executable, l:linter, l:next_chain_index, l:output)
|
||||
let [l:command, l:options] = ale#engine#ProcessChain(
|
||||
\ a:buffer,
|
||||
\ l:executable,
|
||||
\ l:linter,
|
||||
\ l:next_chain_index,
|
||||
\ a:output,
|
||||
\)
|
||||
|
||||
call s:RunJob(l:command, l:options)
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
" Log the output of the command for ALEInfo if we should.
|
||||
if g:ale_history_enabled && g:ale_history_log_output
|
||||
call ale#history#RememberOutput(l:buffer, a:job_id, l:output[:])
|
||||
endif
|
||||
|
||||
try
|
||||
let l:loclist = ale#util#GetFunction(l:linter.callback)(l:buffer, l:output)
|
||||
let l:loclist = ale#util#GetFunction(l:linter.callback)(a:buffer, a:output)
|
||||
" Handle the function being unknown, or being deleted.
|
||||
catch /E700/
|
||||
let l:loclist = []
|
||||
endtry
|
||||
|
||||
call ale#engine#HandleLoclist(l:linter.name, l:buffer, l:loclist, 0)
|
||||
call ale#engine#HandleLoclist(l:linter.name, a:buffer, l:loclist, 0)
|
||||
endfunction
|
||||
|
||||
function! ale#engine#SetResults(buffer, loclist) abort
|
||||
@@ -321,7 +265,7 @@ function! ale#engine#SetResults(buffer, loclist) abort
|
||||
|
||||
" Automatically remove all managed temporary files and directories
|
||||
" now that all jobs have completed.
|
||||
call ale#engine#RemoveManagedFiles(a:buffer)
|
||||
call ale#command#RemoveManagedFiles(a:buffer)
|
||||
|
||||
" Call user autocommands. This allows users to hook into ALE's lint cycle.
|
||||
silent doautocmd <nomodeline> User ALELintPost
|
||||
@@ -472,33 +416,23 @@ endfunction
|
||||
" Given part of a command, replace any % with %%, so that no characters in
|
||||
" the string will be replaced with filenames, etc.
|
||||
function! ale#engine#EscapeCommandPart(command_part) abort
|
||||
return substitute(a:command_part, '%', '%%', 'g')
|
||||
endfunction
|
||||
|
||||
function! s:CreateTemporaryFileForJob(buffer, temporary_file) abort
|
||||
if empty(a:temporary_file)
|
||||
" There is no file, so we didn't create anything.
|
||||
return 0
|
||||
endif
|
||||
|
||||
let l:temporary_directory = fnamemodify(a:temporary_file, ':h')
|
||||
" Create the temporary directory for the file, unreadable by 'other'
|
||||
" users.
|
||||
call mkdir(l:temporary_directory, '', 0750)
|
||||
" Automatically delete the directory later.
|
||||
call ale#engine#ManageDirectory(a:buffer, l:temporary_directory)
|
||||
" Write the buffer out to a file.
|
||||
let l:lines = getbufline(a:buffer, 1, '$')
|
||||
call ale#util#Writefile(a:buffer, l:lines, a:temporary_file)
|
||||
|
||||
return 1
|
||||
" TODO: Emit deprecation warning here later.
|
||||
return ale#command#EscapeCommandPart(a:command_part)
|
||||
endfunction
|
||||
|
||||
" Run a job.
|
||||
"
|
||||
" Returns 1 when the job was started successfully.
|
||||
function! s:RunJob(options) abort
|
||||
let l:command = a:options.command
|
||||
" 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)
|
||||
return 0
|
||||
@@ -512,201 +446,106 @@ function! s:RunJob(options) abort
|
||||
let l:read_buffer = a:options.read_buffer
|
||||
let l:info = g:ale_buffer_info[l:buffer]
|
||||
|
||||
let [l:temporary_file, l:command] = ale#command#FormatCommand(
|
||||
\ l:buffer,
|
||||
\ l:executable,
|
||||
\ l:command,
|
||||
\ l:read_buffer,
|
||||
\)
|
||||
|
||||
if s:CreateTemporaryFileForJob(l:buffer, l:temporary_file)
|
||||
" If a temporary filename has been formatted in to the command, then
|
||||
" we do not need to send the Vim buffer to the command.
|
||||
let l:read_buffer = 0
|
||||
endif
|
||||
|
||||
" Add a newline to commands which need it.
|
||||
" This is only used for Flow for now, and is not documented.
|
||||
if l:linter.add_newline
|
||||
if has('win32')
|
||||
let l:command = l:command . '; echo.'
|
||||
else
|
||||
let l:command = l:command . '; echo'
|
||||
endif
|
||||
endif
|
||||
|
||||
let l:command = ale#job#PrepareCommand(l:buffer, l:command)
|
||||
let l:job_options = {
|
||||
\ 'mode': 'nl',
|
||||
\ 'exit_cb': function('s:HandleExit'),
|
||||
\}
|
||||
|
||||
if l:output_stream is# 'stderr'
|
||||
let l:job_options.err_cb = function('s:GatherOutput')
|
||||
elseif l:output_stream is# 'both'
|
||||
let l:job_options.out_cb = function('s:GatherOutput')
|
||||
let l:job_options.err_cb = function('s:GatherOutput')
|
||||
else
|
||||
let l:job_options.out_cb = function('s:GatherOutput')
|
||||
endif
|
||||
|
||||
if get(g:, 'ale_run_synchronously') == 1
|
||||
" Find a unique Job value to use, which will be the same as the ID for
|
||||
" running commands synchronously. This is only for test code.
|
||||
let l:job_id = len(s:job_info_map) + 1
|
||||
|
||||
while has_key(s:job_info_map, l:job_id)
|
||||
let l:job_id += 1
|
||||
endwhile
|
||||
else
|
||||
let l:job_id = ale#job#Start(l:command, l:job_options)
|
||||
endif
|
||||
|
||||
let l:status = 'failed'
|
||||
let l:Callback = function('s:HandleExit', [{
|
||||
\ 'linter': l:linter,
|
||||
\ 'executable': l:executable,
|
||||
\ 'next_chain_index': l:next_chain_index,
|
||||
\}])
|
||||
let l:result = ale#command#Run(l:buffer, l:command, l:Callback, {
|
||||
\ 'output_stream': l:output_stream,
|
||||
\ 'executable': l:executable,
|
||||
\ 'read_buffer': l:read_buffer,
|
||||
\ 'log_output': l:next_chain_index >= len(get(l:linter, 'command_chain', [])),
|
||||
\})
|
||||
|
||||
" Only proceed if the job is being run.
|
||||
if l:job_id
|
||||
" Add the job to the list of jobs, so we can track them.
|
||||
call add(l:info.job_list, l:job_id)
|
||||
|
||||
if index(l:info.active_linter_list, l:linter.name) < 0
|
||||
call add(l:info.active_linter_list, l:linter.name)
|
||||
endif
|
||||
|
||||
let l:status = 'started'
|
||||
" Store the ID for the job in the map to read back again.
|
||||
let s:job_info_map[l:job_id] = {
|
||||
\ 'linter': l:linter,
|
||||
\ 'buffer': l:buffer,
|
||||
\ 'executable': l:executable,
|
||||
\ 'output': [],
|
||||
\ 'next_chain_index': l:next_chain_index,
|
||||
\}
|
||||
|
||||
silent doautocmd <nomodeline> User ALEJobStarted
|
||||
if empty(l:result)
|
||||
return 0
|
||||
endif
|
||||
|
||||
if g:ale_history_enabled
|
||||
call ale#history#Add(l:buffer, l:status, l:job_id, l:command)
|
||||
endif
|
||||
call ale#engine#MarkLinterActive(l:info, l:linter)
|
||||
|
||||
if get(g:, 'ale_run_synchronously') == 1
|
||||
" Run a command synchronously if this test option is set.
|
||||
let s:job_info_map[l:job_id].output = systemlist(
|
||||
\ type(l:command) is v:t_list
|
||||
\ ? join(l:command[0:1]) . ' ' . ale#Escape(l:command[2])
|
||||
\ : l:command
|
||||
\)
|
||||
silent doautocmd <nomodeline> User ALEJobStarted
|
||||
|
||||
call l:job_options.exit_cb(l:job_id, v:shell_error)
|
||||
endif
|
||||
|
||||
return l:job_id != 0
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
" Determine which commands to run for a link in a command chain, or
|
||||
" just a regular command.
|
||||
function! ale#engine#ProcessChain(buffer, linter, chain_index, input) abort
|
||||
function! ale#engine#ProcessChain(buffer, executable, linter, chain_index, input) abort
|
||||
let l:output_stream = get(a:linter, 'output_stream', 'stdout')
|
||||
let l:read_buffer = a:linter.read_buffer
|
||||
let l:chain_index = a:chain_index
|
||||
let l:input = a:input
|
||||
|
||||
if has_key(a:linter, 'command_chain')
|
||||
while l:chain_index < len(a:linter.command_chain)
|
||||
" Run a chain of commands, one asynchronous command after the other,
|
||||
" so that many programs can be run in a sequence.
|
||||
let l:chain_item = a:linter.command_chain[l:chain_index]
|
||||
while l:chain_index < len(a:linter.command_chain)
|
||||
" Run a chain of commands, one asynchronous command after the other,
|
||||
" so that many programs can be run in a sequence.
|
||||
let l:chain_item = a:linter.command_chain[l:chain_index]
|
||||
|
||||
if l:chain_index == 0
|
||||
" The first callback in the chain takes only a buffer number.
|
||||
let l:command = ale#util#GetFunction(l:chain_item.callback)(
|
||||
\ a:buffer
|
||||
\)
|
||||
else
|
||||
" The second callback in the chain takes some input too.
|
||||
let l:command = ale#util#GetFunction(l:chain_item.callback)(
|
||||
\ a:buffer,
|
||||
\ l:input
|
||||
\)
|
||||
if l:chain_index == 0
|
||||
" The first callback in the chain takes only a buffer number.
|
||||
let l:command = ale#util#GetFunction(l:chain_item.callback)(
|
||||
\ a:buffer
|
||||
\)
|
||||
else
|
||||
" The second callback in the chain takes some input too.
|
||||
let l:command = ale#util#GetFunction(l:chain_item.callback)(
|
||||
\ a:buffer,
|
||||
\ l:input
|
||||
\)
|
||||
endif
|
||||
|
||||
" If we have a command to run, execute that.
|
||||
if !empty(l:command)
|
||||
" The chain item can override the output_stream option.
|
||||
if has_key(l:chain_item, 'output_stream')
|
||||
let l:output_stream = l:chain_item.output_stream
|
||||
endif
|
||||
|
||||
" If we have a command to run, execute that.
|
||||
if !empty(l:command)
|
||||
" The chain item can override the output_stream option.
|
||||
if has_key(l:chain_item, 'output_stream')
|
||||
let l:output_stream = l:chain_item.output_stream
|
||||
endif
|
||||
|
||||
" The chain item can override the read_buffer option.
|
||||
if has_key(l:chain_item, 'read_buffer')
|
||||
let l:read_buffer = l:chain_item.read_buffer
|
||||
elseif l:chain_index != len(a:linter.command_chain) - 1
|
||||
" Don't read the buffer for commands besides the last one
|
||||
" in the chain by default.
|
||||
let l:read_buffer = 0
|
||||
endif
|
||||
|
||||
break
|
||||
" The chain item can override the read_buffer option.
|
||||
if has_key(l:chain_item, 'read_buffer')
|
||||
let l:read_buffer = l:chain_item.read_buffer
|
||||
elseif l:chain_index != len(a:linter.command_chain) - 1
|
||||
" Don't read the buffer for commands besides the last one
|
||||
" in the chain by default.
|
||||
let l:read_buffer = 0
|
||||
endif
|
||||
|
||||
" Command chain items can return an empty string to indicate that
|
||||
" a command should be skipped, so we should try the next item
|
||||
" with no input.
|
||||
let l:input = []
|
||||
let l:chain_index += 1
|
||||
endwhile
|
||||
else
|
||||
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
|
||||
endif
|
||||
break
|
||||
endif
|
||||
|
||||
return {
|
||||
\ 'command': l:command,
|
||||
" Command chain items can return an empty string to indicate that
|
||||
" a command should be skipped, so we should try the next item
|
||||
" with no input.
|
||||
let l:input = []
|
||||
let l:chain_index += 1
|
||||
endwhile
|
||||
|
||||
return [l:command, {
|
||||
\ 'executable': a:executable,
|
||||
\ 'buffer': a:buffer,
|
||||
\ 'linter': a:linter,
|
||||
\ 'output_stream': l:output_stream,
|
||||
\ 'next_chain_index': l:chain_index + 1,
|
||||
\ 'read_buffer': l:read_buffer,
|
||||
\}
|
||||
\}]
|
||||
endfunction
|
||||
|
||||
function! s:InvokeChain(buffer, executable, linter, chain_index, input) abort
|
||||
let l:options = ale#engine#ProcessChain(a:buffer, a:linter, a:chain_index, a:input)
|
||||
let l:options.executable = a:executable
|
||||
|
||||
return s:RunJob(l:options)
|
||||
endfunction
|
||||
|
||||
function! s:StopCurrentJobs(buffer, include_lint_file_jobs) abort
|
||||
function! s:StopCurrentJobs(buffer, clear_lint_file_jobs) abort
|
||||
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||
let l:new_job_list = []
|
||||
let l:new_active_linter_list = []
|
||||
call ale#command#StopJobs(a:buffer, 'linter')
|
||||
|
||||
for l:job_id in get(l:info, 'job_list', [])
|
||||
let l:job_info = get(s:job_info_map, l:job_id, {})
|
||||
|
||||
if !empty(l:job_info)
|
||||
if a:include_lint_file_jobs || !l:job_info.linter.lint_file
|
||||
call ale#job#Stop(l:job_id)
|
||||
call remove(s:job_info_map, l:job_id)
|
||||
else
|
||||
call add(l:new_job_list, l:job_id)
|
||||
" Linters with jobs still running are still active.
|
||||
call add(l:new_active_linter_list, l:job_info.linter.name)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Remove duplicates from the active linter list.
|
||||
call uniq(sort(l:new_active_linter_list))
|
||||
|
||||
" Update the List, so it includes only the jobs we still need.
|
||||
let l:info.job_list = l:new_job_list
|
||||
" Update the active linter list, clearing out anything not running.
|
||||
let l:info.active_linter_list = l:new_active_linter_list
|
||||
if a:clear_lint_file_jobs
|
||||
call ale#command#StopJobs(a:buffer, 'file_linter')
|
||||
let l:info.active_linter_list = []
|
||||
else
|
||||
" Keep jobs for linting files when we're only linting buffers.
|
||||
call filter(l:info.active_linter_list, 'get(v:val, ''lint_file'')')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
function! s:RemoveProblemsForDisabledLinters(buffer, linters) abort
|
||||
" Figure out which linters are still enabled, and remove
|
||||
" problems for linters which are no longer enabled.
|
||||
@@ -757,6 +596,48 @@ function! s:AddProblemsFromOtherBuffers(buffer, linters) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:RunIfExecutable(buffer, linter, executable) abort
|
||||
if ale#command#IsDeferred(a:executable)
|
||||
let a:executable.result_callback = {
|
||||
\ executable -> s:RunIfExecutable(a:buffer, a:linter, executable)
|
||||
\}
|
||||
|
||||
return 1
|
||||
endif
|
||||
|
||||
if ale#engine#IsExecutable(a:buffer, a:executable)
|
||||
" Use different job types for file or linter jobs.
|
||||
let l:job_type = a:linter.lint_file ? 'file_linter' : 'linter'
|
||||
call setbufvar(a:buffer, 'ale_job_type', l:job_type)
|
||||
|
||||
if has_key(a:linter, 'command_chain')
|
||||
let [l:command, l:options] = ale#engine#ProcessChain(
|
||||
\ a:buffer,
|
||||
\ a:executable,
|
||||
\ a:linter,
|
||||
\ 0,
|
||||
\ []
|
||||
\)
|
||||
|
||||
return s:RunJob(l:command, l:options)
|
||||
endif
|
||||
|
||||
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
|
||||
let l:options = {
|
||||
\ 'executable': a:executable,
|
||||
\ 'buffer': a:buffer,
|
||||
\ 'linter': a:linter,
|
||||
\ 'output_stream': get(a:linter, 'output_stream', 'stdout'),
|
||||
\ 'next_chain_index': 1,
|
||||
\ 'read_buffer': a:linter.read_buffer,
|
||||
\}
|
||||
|
||||
return s:RunJob(l:command, l:options)
|
||||
endif
|
||||
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Run a linter for a buffer.
|
||||
"
|
||||
" Returns 1 if the linter was successfully run.
|
||||
@@ -766,9 +647,7 @@ function! s:RunLinter(buffer, linter) abort
|
||||
else
|
||||
let l:executable = ale#linter#GetExecutable(a:buffer, a:linter)
|
||||
|
||||
if ale#engine#IsExecutable(a:buffer, l:executable)
|
||||
return s:InvokeChain(a:buffer, l:executable, a:linter, 0, [])
|
||||
endif
|
||||
return s:RunIfExecutable(a:buffer, a:linter, l:executable)
|
||||
endif
|
||||
|
||||
return 0
|
||||
@@ -836,90 +715,3 @@ function! ale#engine#GetLoclist(buffer) abort
|
||||
|
||||
return g:ale_buffer_info[a:buffer].loclist
|
||||
endfunction
|
||||
|
||||
" This function can be called with a timeout to wait for all jobs to finish.
|
||||
" If the jobs to not finish in the given number of milliseconds,
|
||||
" an exception will be thrown.
|
||||
"
|
||||
" The time taken will be a very rough approximation, and more time may be
|
||||
" permitted than is specified.
|
||||
function! ale#engine#WaitForJobs(deadline) abort
|
||||
let l:start_time = ale#events#ClockMilliseconds()
|
||||
|
||||
if l:start_time == 0
|
||||
throw 'Failed to read milliseconds from the clock!'
|
||||
endif
|
||||
|
||||
let l:job_list = []
|
||||
|
||||
" Gather all of the jobs from every buffer.
|
||||
for l:info in values(g:ale_buffer_info)
|
||||
call extend(l:job_list, get(l:info, 'job_list', []))
|
||||
endfor
|
||||
|
||||
" NeoVim has a built-in API for this, so use that.
|
||||
if has('nvim')
|
||||
let l:nvim_code_list = jobwait(l:job_list, a:deadline)
|
||||
|
||||
if index(l:nvim_code_list, -1) >= 0
|
||||
throw 'Jobs did not complete on time!'
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
let l:should_wait_more = 1
|
||||
|
||||
while l:should_wait_more
|
||||
let l:should_wait_more = 0
|
||||
|
||||
for l:job_id in l:job_list
|
||||
if ale#job#IsRunning(l:job_id)
|
||||
let l:now = ale#events#ClockMilliseconds()
|
||||
|
||||
if l:now - l:start_time > a:deadline
|
||||
" Stop waiting after a timeout, so we don't wait forever.
|
||||
throw 'Jobs did not complete on time!'
|
||||
endif
|
||||
|
||||
" Wait another 10 milliseconds
|
||||
let l:should_wait_more = 1
|
||||
sleep 10ms
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endwhile
|
||||
|
||||
" Sleep for a small amount of time after all jobs finish.
|
||||
" This seems to be enough to let handlers after jobs end run, and
|
||||
" prevents the occasional failure where this function exits after jobs
|
||||
" end, but before handlers are run.
|
||||
sleep 10ms
|
||||
|
||||
" We must check the buffer data again to see if new jobs started
|
||||
" for command_chain linters.
|
||||
let l:has_new_jobs = 0
|
||||
|
||||
" Check again to see if any jobs are running.
|
||||
for l:info in values(g:ale_buffer_info)
|
||||
for l:job_id in get(l:info, 'job_list', [])
|
||||
if ale#job#IsRunning(l:job_id)
|
||||
let l:has_new_jobs = 1
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
|
||||
if l:has_new_jobs
|
||||
" We have to wait more. Offset the timeout by the time taken so far.
|
||||
let l:now = ale#events#ClockMilliseconds()
|
||||
let l:new_deadline = a:deadline - (l:now - l:start_time)
|
||||
|
||||
if l:new_deadline <= 0
|
||||
" Enough time passed already, so stop immediately.
|
||||
throw 'Jobs did not complete on time!'
|
||||
endif
|
||||
|
||||
call ale#engine#WaitForJobs(l:new_deadline)
|
||||
endif
|
||||
endfunction
|
||||
Reference in new issue
Block a user