#653 Set loclists better when taking data from previous buffers

This commit is contained in:
w0rp 2017-08-22 22:45:55 +01:00
parent 80c7fbcefe
commit 0507503aa7
2 changed files with 52 additions and 9 deletions

View File

@ -728,7 +728,10 @@ function! s:AddProblemsFromOtherBuffers(buffer, linters) abort
if has_key(l:item, 'filename')
\&& l:item.filename is# l:filename
\&& has_key(l:name_map, l:item.linter_name)
call add(l:loclist, l:item)
" Copy the items and set the buffer numbers to this one.
let l:new_item = copy(l:item)
let l:new_item.bufnr = a:buffer
call add(l:loclist, l:new_item)
endif
endfor
endfor
@ -737,6 +740,8 @@ function! s:AddProblemsFromOtherBuffers(buffer, linters) abort
call sort(l:loclist, function('ale#util#LocItemCompareWithText'))
call uniq(l:loclist, function('ale#util#LocItemCompareWithText'))
" Set the loclist variable, used by some parts of ALE.
let g:ale_buffer_info[a:buffer].loclist = l:loclist
call ale#engine#SetResults(a:buffer, l:loclist)
endif
endfunction

View File

@ -1,6 +1,9 @@
Before:
Save g:ale_buffer_info
Save &filetype
Save g:ale_set_lists_synchronously
let g:ale_set_lists_synchronously = 1
" Set up items in other buffers which should set in this one.
let g:ale_buffer_info = {}
@ -13,7 +16,7 @@ Before:
\ ])
call ale#engine#InitBufferInfo(bufnr('') + 2)
let g:ale_buffer_info[bufnr('') + 2].loclist =
\ ale#engine#FixLocList(bufnr('') + 2, 'linter_two', [
\ ale#engine#FixLocList(bufnr('') + 2, 'linter_one', [
\ {'lnum': 1, 'filename': expand('%:p'), 'text': 'foo'},
\ {'lnum': 3, 'filename': expand('%:p'), 'text': 'baz'},
\ {'lnum': 5, 'text': 'ignore this one'},
@ -23,15 +26,9 @@ Before:
\ 'name': 'linter_one',
\ 'callback': 'WhoCares',
\ 'executable': 'echo',
\ 'command': 'echo',
\ 'command': 'sleep 1000',
\ 'lint_file': 1,
\})
call ale#linter#Define('foobar', {
\ 'name': 'linter_two',
\ 'callback': 'WhoCares',
\ 'executable': 'echo',
\ 'command': 'echo',
\})
After:
call ale#engine#Cleanup(bufnr(''))
@ -51,6 +48,47 @@ Given foobar(A file with some lines):
Execute(Problems found from previously opened buffers should be set when linting for the first time):
call ale#engine#RunLinters(bufnr(''), ale#linter#Get(&filetype), 0)
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'bufnr': bufnr(''),
\ 'col': 0,
\ 'filename': expand('%:p'),
\ 'linter_name': 'linter_one',
\ 'nr': -1,
\ 'type': 'E',
\ 'vcol': 0,
\ 'text': 'foo',
\ 'sign_id': 1000001,
\ },
\ {
\ 'lnum': 2,
\ 'bufnr': bufnr(''),
\ 'col': 0,
\ 'filename': expand('%:p'),
\ 'linter_name': 'linter_one',
\ 'nr': -1,
\ 'type': 'E',
\ 'vcol': 0,
\ 'text': 'bar',
\ 'sign_id': 1000002,
\ },
\ {
\ 'lnum': 3,
\ 'bufnr': bufnr(''),
\ 'col': 0,
\ 'filename': expand('%:p'),
\ 'linter_name': 'linter_one',
\ 'nr': -1,
\ 'type': 'E',
\ 'vcol': 0,
\ 'text': 'baz',
\ 'sign_id': 1000003,
\ },
\ ],
\ g:ale_buffer_info[bufnr('')].loclist
AssertEqual
\ [
\ {'lnum': 1, 'bufnr': bufnr(''), 'col': 0, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': 'E', 'pattern': '', 'text': 'foo'},