Simplify code for marking linters as active

This commit is contained in:
w0rp 2019-02-14 10:10:46 +00:00
parent 3140abcd0c
commit 7487ecb957
No known key found for this signature in database
GPG key ID: 0FC1ECAA8C81CD83
3 changed files with 34 additions and 42 deletions

View file

@ -24,6 +24,25 @@ function! ale#engine#CleanupEveryBuffer() abort
endfor endfor
endfunction 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 function! ale#engine#ResetExecutableCache() abort
let s:executable_cache_map = {} let s:executable_cache_map = {}
endfunction endfunction
@ -164,7 +183,7 @@ function! s:HandleExit(job_info, buffer, output, data) abort
let l:next_chain_index = a:job_info.next_chain_index let l:next_chain_index = a:job_info.next_chain_index
" Remove this job from the list. " Remove this job from the list.
call filter(l:buffer_info.active_linter_list, 'v:val.name 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 " Stop here if we land in the handle for a job completing if we're in
" a sandbox. " a sandbox.
@ -431,23 +450,12 @@ function! s:RunJob(command, options) abort
\ 'log_output': l:next_chain_index >= len(get(l:linter, 'command_chain', [])), \ 'log_output': l:next_chain_index >= len(get(l:linter, 'command_chain', [])),
\}) \})
" Only proceed if the job is being run.
if !l:result._deferred_job_id if !l:result._deferred_job_id
return 0 return 0
endif endif
" Only proceed if the job is being run. call ale#engine#MarkLinterActive(l:info, l:linter)
let l:found = 0
for l:other_linter in l:info.active_linter_list
if l:other_linter.name is# l:linter.name
let l:found = 1
break
endif
endfor
if !l:found
call add(l:info.active_linter_list, l:linter)
endif
silent doautocmd <nomodeline> User ALEJobStarted silent doautocmd <nomodeline> User ALEJobStarted
@ -516,25 +524,18 @@ function! ale#engine#ProcessChain(buffer, executable, linter, chain_index, input
\}] \}]
endfunction 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, {})
call ale#command#StopJobs(a:buffer, 'linter') call ale#command#StopJobs(a:buffer, 'linter')
if a:include_lint_file_jobs
call ale#command#StopJobs(a:buffer, 'file_linter')
endif
let l:info = get(g:ale_buffer_info, a:buffer, {})
let l:new_active_linter_list = []
for l:linter in get(l:info, 'active_linter_list', [])
" Keep jobs for linting files when we're only linting buffers.
if !a:include_lint_file_jobs && get(l:linter, 'lint_file')
call add(l:new_active_linter_list, l:linter)
endif
endfor
" Update the active linter list, clearing out anything not running. " 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 endfunction
function! s:RemoveProblemsForDisabledLinters(buffer, linters) abort function! s:RemoveProblemsForDisabledLinters(buffer, linters) abort

View file

@ -294,18 +294,7 @@ function! s:CheckWithLSP(linter, details) abort
endif endif
if l:notified if l:notified
let l:found = 0 call ale#engine#MarkLinterActive(l:info, a:linter)
for l:other_linter in l: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(l:info.active_linter_list, a:linter)
endif
endif endif
endfunction endfunction

View file

@ -8,6 +8,8 @@ Before:
Save g:ale_set_quickfix Save g:ale_set_quickfix
Save g:ale_set_signs Save g:ale_set_signs
let g:ale_buffer_info = {}
" Enable only the one feature we need. " Enable only the one feature we need.
let g:ale_set_signs = 0 let g:ale_set_signs = 0
let g:ale_set_quickfix = 0 let g:ale_set_quickfix = 0