Fix #719 - Add ALEReset and ALEResetBuffer for removing problems for all buffers or one buffer

This commit is contained in:
w0rp 2017-10-29 17:03:29 +00:00
parent 1aa737cdc9
commit daecbad543
4 changed files with 100 additions and 16 deletions

View File

@ -110,25 +110,28 @@ function! s:DisablePostamble() abort
endif endif
endfunction endfunction
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
" functions.
let l:buffer = str2nr(l:key)
if l:buffer > 0
" Stop all jobs and clear the results for everything, and delete
" all of the data we stored for the buffer.
call ale#engine#Cleanup(l:buffer)
endif
endfor
endfunction
function! ale#toggle#Toggle() abort function! ale#toggle#Toggle() abort
let g:ale_enabled = !get(g:, 'ale_enabled') let g:ale_enabled = !get(g:, 'ale_enabled')
if g:ale_enabled if g:ale_enabled
call s:EnablePreamble() call s:EnablePreamble()
else else
for l:key in keys(g:ale_buffer_info) call s:CleanupEveryBuffer()
" 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
" functions.
let l:buffer = str2nr(l:key)
if l:buffer > 0
" Stop all jobs and clear the results for everything, and delete
" all of the data we stored for the buffer.
call ale#engine#Cleanup(l:buffer)
endif
endfor
call s:DisablePostamble() call s:DisablePostamble()
endif endif
@ -152,6 +155,11 @@ function! ale#toggle#Disable() abort
endif endif
endfunction endfunction
function! ale#toggle#Reset() abort
call s:CleanupEveryBuffer()
call ale#highlight#UpdateHighlights()
endfunction
function! ale#toggle#ToggleBuffer(buffer) abort function! ale#toggle#ToggleBuffer(buffer) abort
" Get the new value for the toggle. " Get the new value for the toggle.
let l:enabled = !getbufvar(a:buffer, 'ale_enabled', 1) 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 " Stop all jobs and clear the results for everything, and delete
" all of the data we stored for the buffer. " all of the data we stored for the buffer.
call ale#engine#Cleanup(a:buffer) call ale#engine#Cleanup(a:buffer)
call s:DisablePostamble() call s:DisablePostamble()
endif endif
endfunction endfunction
@ -188,3 +195,8 @@ function! ale#toggle#DisableBuffer(buffer) abort
call ale#toggle#ToggleBuffer(a:buffer) call ale#toggle#ToggleBuffer(a:buffer)
endif endif
endfunction endfunction
function! ale#toggle#ResetBuffer(buffer) abort
call ale#engine#Cleanup(a:buffer)
call ale#highlight#UpdateHighlights()
endfunction

View File

@ -1468,8 +1468,7 @@ ALEDisableBuffer *ALEDisableBuffer*
globally, as disabling ALE globally removes the autocmd events needed to globally, as disabling ALE globally removes the autocmd events needed to
perform linting with. perform linting with.
The following plug mappings are defined, for conveniently defining The following plug mappings are defined, for conveniently defining keybinds:
keybinds:
|ALEToggle| - `<Plug>(ale_toggle)` |ALEToggle| - `<Plug>(ale_toggle)`
|ALEEnable| - `<Plug>(ale_enable)` |ALEEnable| - `<Plug>(ale_enable)`
@ -1478,6 +1477,8 @@ ALEDisableBuffer *ALEDisableBuffer*
|ALEEnableBuffer| - `<Plug>(ale_enable_buffer)` |ALEEnableBuffer| - `<Plug>(ale_enable_buffer)`
|ALEDisableBuffer| - `<Plug>(ale_disable_buffer)` |ALEDisableBuffer| - `<Plug>(ale_disable_buffer)`
For removing problems reported by ALE, but leaving ALE enabled, see
|ALEReset| and |ALEResetBuffer|.
ALEDetail *ALEDetail* ALEDetail *ALEDetail*
@ -1505,6 +1506,24 @@ ALEInfoToClipboard *ALEInfoToClipboard*
your clipboard. This might not work on every machine. 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* 9. API *ale-api*

View File

@ -224,10 +224,12 @@ command! -bar ALEDetail :call ale#cursor#ShowCursorDetail()
command! -bar ALEToggle :call ale#toggle#Toggle() command! -bar ALEToggle :call ale#toggle#Toggle()
command! -bar ALEEnable :call ale#toggle#Enable() command! -bar ALEEnable :call ale#toggle#Enable()
command! -bar ALEDisable :call ale#toggle#Disable() command! -bar ALEDisable :call ale#toggle#Disable()
command! -bar ALEReset :call ale#toggle#Reset()
" Commands for turning ALE on or off for a buffer. " Commands for turning ALE on or off for a buffer.
command! -bar ALEToggleBuffer :call ale#toggle#ToggleBuffer(bufnr('')) command! -bar ALEToggleBuffer :call ale#toggle#ToggleBuffer(bufnr(''))
command! -bar ALEEnableBuffer :call ale#toggle#EnableBuffer(bufnr('')) command! -bar ALEEnableBuffer :call ale#toggle#EnableBuffer(bufnr(''))
command! -bar ALEDisableBuffer :call ale#toggle#DisableBuffer(bufnr('')) command! -bar ALEDisableBuffer :call ale#toggle#DisableBuffer(bufnr(''))
command! -bar ALEResetBuffer :call ale#toggle#ResetBuffer(bufnr(''))
" A command for linting manually. " A command for linting manually.
command! -bar ALELint :call ale#Queue(0, 'lint_file') 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_toggle) :ALEToggle<Return>
nnoremap <silent> <Plug>(ale_enable) :ALEEnable<Return> nnoremap <silent> <Plug>(ale_enable) :ALEEnable<Return>
nnoremap <silent> <Plug>(ale_disable) :ALEDisable<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_toggle_buffer) :ALEToggleBuffer<Return>
nnoremap <silent> <Plug>(ale_enable_buffer) :ALEEnableBuffer<Return> nnoremap <silent> <Plug>(ale_enable_buffer) :ALEEnableBuffer<Return>
nnoremap <silent> <Plug>(ale_disable_buffer) :ALEDisableBuffer<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_lint) :ALELint<Return>
nnoremap <silent> <Plug>(ale_detail) :ALEDetail<Return> nnoremap <silent> <Plug>(ale_detail) :ALEDetail<Return>
nnoremap <silent> <Plug>(ale_fix) :ALEFix<Return> nnoremap <silent> <Plug>(ale_fix) :ALEFix<Return>

View File

@ -215,6 +215,30 @@ Execute(ALEEnable should enable ALE and lint again):
AssertEqual g:expected_loclist, getloclist(0) AssertEqual g:expected_loclist, getloclist(0)
AssertEqual 1, g:ale_enabled 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): Execute(ALEToggleBuffer should reset everything and then run again):
" Run this test asynchrously. " Run this test asynchrously.
let g:ale_run_synchronously = 0 let g:ale_run_synchronously = 0
@ -285,3 +309,28 @@ Execute(ALEEnableBuffer should complain when ALE is disabled globally):
AssertEqual AssertEqual
\ 'ALE cannot be enabled locally when disabled globally', \ 'ALE cannot be enabled locally when disabled globally',
\ join(split(g:output)) \ 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)