mirror of https://github.com/dense-analysis/ale
#2017 Simplify lint cycles for supporting other sources later
This commit is contained in:
parent
9dbebf1cb3
commit
2846e86217
106
autoload/ale.vim
106
autoload/ale.vim
|
@ -10,8 +10,7 @@ let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning')
|
|||
let g:ale_linters_ignore = get(g:, 'ale_linters_ignore', {})
|
||||
|
||||
let s:lint_timer = -1
|
||||
let s:queued_buffer_number = -1
|
||||
let s:should_lint_file_for_buffer = {}
|
||||
let s:getcmdwintype_exists = exists('*getcmdwintype')
|
||||
|
||||
" Return 1 if a file is too large for ALE to handle.
|
||||
function! ale#FileTooLarge(buffer) abort
|
||||
|
@ -20,8 +19,6 @@ function! ale#FileTooLarge(buffer) abort
|
|||
return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0
|
||||
endfunction
|
||||
|
||||
let s:getcmdwintype_exists = exists('*getcmdwintype')
|
||||
|
||||
" A function for checking various conditions whereby ALE just shouldn't
|
||||
" attempt to do anything, say if particular buffer types are open in Vim.
|
||||
function! ale#ShouldDoNothing(buffer) abort
|
||||
|
@ -86,18 +83,39 @@ function! ale#ShouldDoNothing(buffer) abort
|
|||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:Lint(buffer, should_lint_file, timer_id) abort
|
||||
" Use the filetype from the buffer
|
||||
let l:filetype = getbufvar(a:buffer, '&filetype')
|
||||
let l:linters = ale#linter#Get(l:filetype)
|
||||
|
||||
" Apply ignore lists for linters only if needed.
|
||||
let l:ignore_config = ale#Var(a:buffer, 'linters_ignore')
|
||||
let l:linters = !empty(l:ignore_config)
|
||||
\ ? ale#engine#ignore#Exclude(l:filetype, l:linters, l:ignore_config)
|
||||
\ : l:linters
|
||||
|
||||
" Don't set up buffer data and so on if there are no linters to run.
|
||||
if !has_key(g:ale_buffer_info, a:buffer) && empty(l:linters)
|
||||
return
|
||||
endif
|
||||
|
||||
" Clear lint_file linters, or only run them if the file exists.
|
||||
let l:lint_file = empty(l:linters)
|
||||
\ || (a:should_lint_file && filereadable(expand('#' . a:buffer . ':p')))
|
||||
|
||||
call ale#engine#RunLinters(a:buffer, l:linters, l:lint_file)
|
||||
endfunction
|
||||
|
||||
" (delay, [linting_flag, buffer_number])
|
||||
function! ale#Queue(delay, ...) abort
|
||||
if a:0 > 2
|
||||
throw 'too many arguments!'
|
||||
endif
|
||||
|
||||
" Default linting_flag to ''
|
||||
let l:linting_flag = get(a:000, 0, '')
|
||||
let l:buffer = get(a:000, 1, bufnr(''))
|
||||
let l:buffer = get(a:000, 1, v:null)
|
||||
|
||||
if l:linting_flag isnot# '' && l:linting_flag isnot# 'lint_file'
|
||||
throw "linting_flag must be either '' or 'lint_file'"
|
||||
if l:buffer is v:null
|
||||
let l:buffer = bufnr('')
|
||||
endif
|
||||
|
||||
if type(l:buffer) isnot v:t_number
|
||||
|
@ -108,80 +126,24 @@ function! ale#Queue(delay, ...) abort
|
|||
return
|
||||
endif
|
||||
|
||||
" Remember that we want to check files for this buffer.
|
||||
" We will remember this until we finally run the linters, via any event.
|
||||
if l:linting_flag is# 'lint_file'
|
||||
let s:should_lint_file_for_buffer[l:buffer] = 1
|
||||
endif
|
||||
" Default linting_flag to ''
|
||||
let l:should_lint_file = get(a:000, 0) is# 'lint_file'
|
||||
|
||||
if s:lint_timer != -1
|
||||
call timer_stop(s:lint_timer)
|
||||
let s:lint_timer = -1
|
||||
endif
|
||||
|
||||
let l:linters = ale#linter#Get(getbufvar(l:buffer, '&filetype'))
|
||||
|
||||
" Don't set up buffer data and so on if there are no linters to run.
|
||||
if empty(l:linters)
|
||||
" If we have some previous buffer data, then stop any jobs currently
|
||||
" running and clear everything.
|
||||
if has_key(g:ale_buffer_info, l:buffer)
|
||||
call ale#engine#RunLinters(l:buffer, [], 1)
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if a:delay > 0
|
||||
let s:queued_buffer_number = l:buffer
|
||||
let s:lint_timer = timer_start(a:delay, function('ale#Lint'))
|
||||
let s:lint_timer = timer_start(
|
||||
\ a:delay,
|
||||
\ function('s:Lint', [l:buffer, l:should_lint_file])
|
||||
\)
|
||||
else
|
||||
call ale#Lint(-1, l:buffer)
|
||||
call s:Lint(l:buffer, l:should_lint_file, 0)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#Lint(...) abort
|
||||
if a:0 > 1
|
||||
" Use the buffer number given as the optional second argument.
|
||||
let l:buffer = a:2
|
||||
elseif a:0 > 0 && a:1 == s:lint_timer
|
||||
" Use the buffer number for the buffer linting was queued for.
|
||||
let l:buffer = s:queued_buffer_number
|
||||
else
|
||||
" Use the current buffer number.
|
||||
let l:buffer = bufnr('')
|
||||
endif
|
||||
|
||||
if ale#ShouldDoNothing(l:buffer)
|
||||
return
|
||||
endif
|
||||
|
||||
" Use the filetype from the buffer
|
||||
let l:filetype = getbufvar(l:buffer, '&filetype')
|
||||
let l:linters = ale#linter#Get(l:filetype)
|
||||
let l:should_lint_file = 0
|
||||
|
||||
" Check if we previously requested checking the file.
|
||||
if has_key(s:should_lint_file_for_buffer, l:buffer)
|
||||
unlet s:should_lint_file_for_buffer[l:buffer]
|
||||
" Lint files if they exist.
|
||||
let l:should_lint_file = filereadable(expand('#' . l:buffer . ':p'))
|
||||
endif
|
||||
|
||||
" Apply ignore lists for linters only if needed.
|
||||
let l:ignore_config = ale#Var(l:buffer, 'linters_ignore')
|
||||
let l:linters = !empty(l:ignore_config)
|
||||
\ ? ale#engine#ignore#Exclude(l:filetype, l:linters, l:ignore_config)
|
||||
\ : l:linters
|
||||
|
||||
call ale#engine#RunLinters(l:buffer, l:linters, l:should_lint_file)
|
||||
endfunction
|
||||
|
||||
" Reset flags indicating that files should be checked for all buffers.
|
||||
function! ale#ResetLintFileMarkers() abort
|
||||
let s:should_lint_file_for_buffer = {}
|
||||
endfunction
|
||||
|
||||
let g:ale_has_override = get(g:, 'ale_has_override', {})
|
||||
|
||||
" Call has(), but check a global Dictionary so we can force flags on or off
|
||||
|
|
|
@ -65,7 +65,7 @@ Execute(Linters should run with the default options):
|
|||
" Try the test a few times over in NeoVim 0.3 or Windows,
|
||||
" where tests fail randomly.
|
||||
for g:i in range(has('nvim-0.3') || has('win32') ? 5 : 1)
|
||||
call ale#Lint()
|
||||
call ale#Queue(0, '')
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
let g:results = ale#test#GetLoclistWithoutModule()
|
||||
|
@ -109,7 +109,7 @@ Execute(Linters should run in PowerShell too):
|
|||
\ 'command': 'echo foo && echo bar',
|
||||
\})
|
||||
|
||||
call ale#Lint()
|
||||
call ale#Queue(0, '')
|
||||
call ale#engine#WaitForJobs(4000)
|
||||
|
||||
AssertEqual [
|
||||
|
@ -139,7 +139,7 @@ Execute(Linters should run in PowerShell too):
|
|||
endif
|
||||
|
||||
Execute(Previous errors should be removed when linters change):
|
||||
call ale#Lint()
|
||||
call ale#Queue(0, '')
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
call ale#linter#Reset()
|
||||
|
@ -166,7 +166,7 @@ Execute(Previous errors should be removed when linters change):
|
|||
" Try the test a few times over in NeoVim 0.3 or Windows,
|
||||
" where tests fail randomly.
|
||||
for g:i in range(has('nvim-0.3') || has('win32') ? 5 : 1)
|
||||
call ale#Lint()
|
||||
call ale#Queue(0, '')
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
let g:results = ale#test#GetLoclistWithoutModule()
|
||||
|
|
|
@ -14,7 +14,7 @@ After:
|
|||
catch
|
||||
endtry
|
||||
|
||||
Given foobar(An empty file):
|
||||
Given testft(An empty file):
|
||||
Execute(Run a lint cycle, and check that a variable is set in the autocmd):
|
||||
augroup VaderTest
|
||||
autocmd!
|
||||
|
@ -22,7 +22,7 @@ Execute(Run a lint cycle, and check that a variable is set in the autocmd):
|
|||
autocmd User ALELintPost let g:post_success = 1
|
||||
augroup end
|
||||
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
|
||||
AssertEqual g:pre_success, 1
|
||||
AssertEqual g:post_success, 1
|
||||
|
@ -30,10 +30,10 @@ Execute(Run a lint cycle, and check that a variable is set in the autocmd):
|
|||
Execute(b:ale_linted should be increased after each lint cycle):
|
||||
AssertEqual get(b:, 'ale_linted'), 0
|
||||
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
|
||||
AssertEqual get(b:, 'ale_linted'), 1
|
||||
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
|
||||
AssertEqual get(b:, 'ale_linted'), 2
|
||||
|
|
|
@ -62,7 +62,7 @@ Given foobar (Some imaginary filetype):
|
|||
|
||||
Execute(Check the results of running the chain):
|
||||
AssertEqual 'foobar', &filetype
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
|
||||
Assert g:first_echo_called, 'The first chain item was not called'
|
||||
Assert g:second_echo_called, 'The second chain item was not called'
|
||||
|
|
|
@ -73,7 +73,7 @@ Execute(History should be set when commands are run):
|
|||
" Retry this test until it works. This one can randomly fail.
|
||||
for g:i in range(has('nvim-0.3') || has('win32') ? 5 : 1)
|
||||
let b:ale_history = []
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
let g:history = filter(
|
||||
|
@ -106,7 +106,7 @@ Execute(History should be not set when disabled):
|
|||
|
||||
let g:ale_history_enabled = 0
|
||||
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
AssertEqual [], ale#history#Get(bufnr(''))
|
||||
|
@ -120,7 +120,7 @@ Execute(History should include command output if logging is enabled):
|
|||
" Retry this test until it works. This one can randomly fail.
|
||||
for g:i in range(has('nvim-0.3') || has('win32') ? 5 : 1)
|
||||
let b:ale_history = []
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
let g:history = ale#history#Get(bufnr(''))
|
||||
|
|
|
@ -138,6 +138,9 @@ After:
|
|||
|
||||
Given foobar(An empty file):
|
||||
Execute(Global ignore lists should be applied for linters):
|
||||
" We have to set up buffer info so RunLinters is called.
|
||||
let g:ale_buffer_info = {bufnr(''): {}}
|
||||
|
||||
ALELint
|
||||
Assert g:run_linters_called, "The mock callback wasn't called"
|
||||
AssertEqual ['testlinter'], map(g:linters, 'v:val.name')
|
||||
|
@ -147,6 +150,9 @@ Execute(Global ignore lists should be applied for linters):
|
|||
AssertEqual [], g:linters
|
||||
|
||||
Execute(buffer ignore lists should be applied for linters):
|
||||
" We have to set up buffer info so RunLinters is called.
|
||||
let g:ale_buffer_info = {bufnr(''): {}}
|
||||
|
||||
ALELint
|
||||
Assert g:run_linters_called, "The mock callback wasn't called"
|
||||
AssertEqual ['testlinter'], map(g:linters, 'v:val.name')
|
||||
|
|
|
@ -10,7 +10,6 @@ Before:
|
|||
let g:ale_run_synchronously = 1
|
||||
let g:ale_set_lists_synchronously = 1
|
||||
let b:ale_save_event_fired = 0
|
||||
call ale#ResetLintFileMarkers()
|
||||
|
||||
let g:buffer_result = [
|
||||
\ {
|
||||
|
|
|
@ -10,7 +10,7 @@ Given unite (A Unite.vim file):
|
|||
anything
|
||||
|
||||
Execute(Running ALE on a blacklisted file shouldn't change anything):
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
AssertEqual {}, g:ale_buffer_info
|
||||
|
|
|
@ -47,7 +47,6 @@ Execute(ALE shouldn't blow up when run from a sandbox):
|
|||
|
||||
sandbox call ale#Queue(0)
|
||||
sandbox call ale#Queue(1)
|
||||
sandbox call ale#Lint()
|
||||
|
||||
Execute(ALE shouldn't blow up if file cleanup happens in a sandbox):
|
||||
" Make a call to an engine function first, so the function will be defined
|
||||
|
|
|
@ -67,7 +67,7 @@ Given foobar (Some imaginary filetype):
|
|||
Execute(ALE should delete managed files/directories appropriately after linting):
|
||||
AssertEqual 'foobar', &filetype
|
||||
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
Assert !filereadable(g:filename), 'The temporary file was not deleted'
|
||||
|
@ -79,7 +79,7 @@ Execute(ALE should delete managed files even if no command is run):
|
|||
|
||||
let g:command = ''
|
||||
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
Assert !filereadable(g:filename), 'The temporary file was not deleted'
|
||||
|
|
|
@ -12,7 +12,7 @@ Execute(Set Verilog Verilator linter additional options to `-sv --default-langua
|
|||
" Additional args for the linter
|
||||
let g:ale_verilog_verilator_options = '-sv --default-language "1800-2012"'
|
||||
|
||||
call ale#Lint()
|
||||
call ale#Queue(0)
|
||||
|
||||
let g:run_cmd = ale_linters#verilog#verilator#GetCommand(bufnr(''))
|
||||
let g:matched = match(g:run_cmd, '\s' . g:ale_verilog_verilator_options . '\s')
|
||||
|
|
Loading…
Reference in New Issue