Fix #719 - Add ALEReset and ALEResetBuffer for removing problems for all buffers or one buffer
This commit is contained in:
parent
1aa737cdc9
commit
daecbad543
@ -110,12 +110,7 @@ function! s:DisablePostamble() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#toggle#Toggle() abort
|
||||
let g:ale_enabled = !get(g:, 'ale_enabled')
|
||||
|
||||
if g:ale_enabled
|
||||
call s:EnablePreamble()
|
||||
else
|
||||
function! s:CleanupEveryBuffer() abort
|
||||
for l:key in keys(g:ale_buffer_info)
|
||||
" The key could be a filename or a buffer number, so try and
|
||||
" convert it to a number. We need a number for the other
|
||||
@ -128,7 +123,15 @@ function! ale#toggle#Toggle() abort
|
||||
call ale#engine#Cleanup(l:buffer)
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! ale#toggle#Toggle() abort
|
||||
let g:ale_enabled = !get(g:, 'ale_enabled')
|
||||
|
||||
if g:ale_enabled
|
||||
call s:EnablePreamble()
|
||||
else
|
||||
call s:CleanupEveryBuffer()
|
||||
call s:DisablePostamble()
|
||||
endif
|
||||
|
||||
@ -152,6 +155,11 @@ function! ale#toggle#Disable() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#toggle#Reset() abort
|
||||
call s:CleanupEveryBuffer()
|
||||
call ale#highlight#UpdateHighlights()
|
||||
endfunction
|
||||
|
||||
function! ale#toggle#ToggleBuffer(buffer) abort
|
||||
" Get the new value for the toggle.
|
||||
let l:enabled = !getbufvar(a:buffer, 'ale_enabled', 1)
|
||||
@ -171,7 +179,6 @@ function! ale#toggle#ToggleBuffer(buffer) abort
|
||||
" Stop all jobs and clear the results for everything, and delete
|
||||
" all of the data we stored for the buffer.
|
||||
call ale#engine#Cleanup(a:buffer)
|
||||
|
||||
call s:DisablePostamble()
|
||||
endif
|
||||
endfunction
|
||||
@ -188,3 +195,8 @@ function! ale#toggle#DisableBuffer(buffer) abort
|
||||
call ale#toggle#ToggleBuffer(a:buffer)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#toggle#ResetBuffer(buffer) abort
|
||||
call ale#engine#Cleanup(a:buffer)
|
||||
call ale#highlight#UpdateHighlights()
|
||||
endfunction
|
||||
|
23
doc/ale.txt
23
doc/ale.txt
@ -1468,8 +1468,7 @@ ALEDisableBuffer *ALEDisableBuffer*
|
||||
globally, as disabling ALE globally removes the autocmd events needed to
|
||||
perform linting with.
|
||||
|
||||
The following plug mappings are defined, for conveniently defining
|
||||
keybinds:
|
||||
The following plug mappings are defined, for conveniently defining keybinds:
|
||||
|
||||
|ALEToggle| - `<Plug>(ale_toggle)`
|
||||
|ALEEnable| - `<Plug>(ale_enable)`
|
||||
@ -1478,6 +1477,8 @@ ALEDisableBuffer *ALEDisableBuffer*
|
||||
|ALEEnableBuffer| - `<Plug>(ale_enable_buffer)`
|
||||
|ALEDisableBuffer| - `<Plug>(ale_disable_buffer)`
|
||||
|
||||
For removing problems reported by ALE, but leaving ALE enabled, see
|
||||
|ALEReset| and |ALEResetBuffer|.
|
||||
|
||||
ALEDetail *ALEDetail*
|
||||
|
||||
@ -1505,6 +1506,24 @@ ALEInfoToClipboard *ALEInfoToClipboard*
|
||||
your clipboard. This might not work on every machine.
|
||||
|
||||
|
||||
ALEReset *ALEReset*
|
||||
ALEResetBuffer *ALEResetBuffer*
|
||||
|
||||
`ALEReset` will remove all problems reported by ALE for all buffers.
|
||||
`ALEResetBuffer` will remove all problems reported for a single buffer.
|
||||
|
||||
Either command will leave ALE linting enabled, so ALE will report problems
|
||||
when linting is performed again. See |ale-lint| for more information.
|
||||
|
||||
The following plug mappings are defined, for conveniently defining keybinds:
|
||||
|
||||
|ALEReset| - `<Plug>(ale_reset)`
|
||||
|ALEResetBuffer| - `<Plug>(ale_reset_buffer)`
|
||||
|
||||
ALE can be disabled globally or for a buffer with |ALEDisable| or
|
||||
|ALEDisableBuffer|.
|
||||
|
||||
|
||||
===============================================================================
|
||||
9. API *ale-api*
|
||||
|
||||
|
@ -224,10 +224,12 @@ command! -bar ALEDetail :call ale#cursor#ShowCursorDetail()
|
||||
command! -bar ALEToggle :call ale#toggle#Toggle()
|
||||
command! -bar ALEEnable :call ale#toggle#Enable()
|
||||
command! -bar ALEDisable :call ale#toggle#Disable()
|
||||
command! -bar ALEReset :call ale#toggle#Reset()
|
||||
" Commands for turning ALE on or off for a buffer.
|
||||
command! -bar ALEToggleBuffer :call ale#toggle#ToggleBuffer(bufnr(''))
|
||||
command! -bar ALEEnableBuffer :call ale#toggle#EnableBuffer(bufnr(''))
|
||||
command! -bar ALEDisableBuffer :call ale#toggle#DisableBuffer(bufnr(''))
|
||||
command! -bar ALEResetBuffer :call ale#toggle#ResetBuffer(bufnr(''))
|
||||
|
||||
" A command for linting manually.
|
||||
command! -bar ALELint :call ale#Queue(0, 'lint_file')
|
||||
@ -252,9 +254,11 @@ nnoremap <silent> <Plug>(ale_last) :ALELast<Return>
|
||||
nnoremap <silent> <Plug>(ale_toggle) :ALEToggle<Return>
|
||||
nnoremap <silent> <Plug>(ale_enable) :ALEEnable<Return>
|
||||
nnoremap <silent> <Plug>(ale_disable) :ALEDisable<Return>
|
||||
nnoremap <silent> <Plug>(ale_reset) :ALEReset<Return>
|
||||
nnoremap <silent> <Plug>(ale_toggle_buffer) :ALEToggleBuffer<Return>
|
||||
nnoremap <silent> <Plug>(ale_enable_buffer) :ALEEnableBuffer<Return>
|
||||
nnoremap <silent> <Plug>(ale_disable_buffer) :ALEDisableBuffer<Return>
|
||||
nnoremap <silent> <Plug>(ale_reset_buffer) :ALEResetBuffer<Return>
|
||||
nnoremap <silent> <Plug>(ale_lint) :ALELint<Return>
|
||||
nnoremap <silent> <Plug>(ale_detail) :ALEDetail<Return>
|
||||
nnoremap <silent> <Plug>(ale_fix) :ALEFix<Return>
|
||||
|
@ -215,6 +215,30 @@ Execute(ALEEnable should enable ALE and lint again):
|
||||
AssertEqual g:expected_loclist, getloclist(0)
|
||||
AssertEqual 1, g:ale_enabled
|
||||
|
||||
Execute(ALEReset should reset everything for a buffer):
|
||||
AssertEqual 'foobar', &filetype
|
||||
|
||||
call ale#Lint()
|
||||
|
||||
" First check that everything is there...
|
||||
AssertEqual g:expected_loclist, getloclist(0)
|
||||
AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
|
||||
AssertEqual
|
||||
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
|
||||
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
|
||||
AssertEqual [{'lnum': 2, 'bufnr': bufnr(''), 'col': 3, 'linter_name': 'testlinter', 'vcol': 0, 'nr': -1, 'type': 'E', 'text': 'foo bar', 'sign_id': 1000001}], g:ale_buffer_info[bufnr('')].loclist
|
||||
|
||||
" Now Toggle ALE off.
|
||||
ALEReset
|
||||
|
||||
" Everything should be cleared.
|
||||
Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
|
||||
AssertEqual [], getloclist(0), 'The loclist was not cleared'
|
||||
AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
|
||||
AssertEqual [], getmatches(), 'The highlights were not cleared'
|
||||
|
||||
AssertEqual 1, g:ale_enabled
|
||||
|
||||
Execute(ALEToggleBuffer should reset everything and then run again):
|
||||
" Run this test asynchrously.
|
||||
let g:ale_run_synchronously = 0
|
||||
@ -285,3 +309,28 @@ Execute(ALEEnableBuffer should complain when ALE is disabled globally):
|
||||
AssertEqual
|
||||
\ 'ALE cannot be enabled locally when disabled globally',
|
||||
\ join(split(g:output))
|
||||
|
||||
Execute(ALEResetBuffer should reset everything for a buffer):
|
||||
AssertEqual 'foobar', &filetype
|
||||
|
||||
call ale#Lint()
|
||||
|
||||
" First check that everything is there...
|
||||
AssertEqual g:expected_loclist, getloclist(0)
|
||||
AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
|
||||
AssertEqual
|
||||
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
|
||||
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
|
||||
AssertEqual [{'lnum': 2, 'bufnr': bufnr(''), 'col': 3, 'linter_name': 'testlinter', 'vcol': 0, 'nr': -1, 'type': 'E', 'text': 'foo bar', 'sign_id': 1000001}], g:ale_buffer_info[bufnr('')].loclist
|
||||
|
||||
" Now Toggle ALE off.
|
||||
ALEResetBuffer
|
||||
|
||||
" Everything should be cleared.
|
||||
Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
|
||||
AssertEqual [], getloclist(0), 'The loclist was not cleared'
|
||||
AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
|
||||
AssertEqual [], getmatches(), 'The highlights were not cleared'
|
||||
|
||||
AssertEqual 1, g:ale_enabled
|
||||
AssertEqual 1, get(b:, 'ale_enabled', 1)
|
||||
|
Loading…
Reference in New Issue
Block a user