mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 13:14:29 +08:00
fix(neovim): ignore unrelated diagnostics (#4597)
Fix the NeoVim diagnostics bridge so it only sends over diagnostics relevant to the current buffer.
This commit is contained in:
@@ -12,6 +12,7 @@ module.sendAleResultsToDiagnostics = function(buffer, loclist)
|
|||||||
-- Convert all the ALE loclist items to the shape that Neovim's diagnostic
|
-- Convert all the ALE loclist items to the shape that Neovim's diagnostic
|
||||||
-- API is expecting.
|
-- API is expecting.
|
||||||
for _, location in ipairs(loclist) do
|
for _, location in ipairs(loclist) do
|
||||||
|
if location.bufnr == buffer then
|
||||||
table.insert(
|
table.insert(
|
||||||
diagnostics,
|
diagnostics,
|
||||||
-- All line numbers from ALE are 1-indexed, but all line numbers
|
-- All line numbers from ALE are 1-indexed, but all line numbers
|
||||||
@@ -35,6 +36,7 @@ module.sendAleResultsToDiagnostics = function(buffer, loclist)
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local virtualtext_enabled_set = {['all'] = true, ['2'] = true, [2] = true, ['current'] = true, ['1'] = true, [1] = true}
|
local virtualtext_enabled_set = {['all'] = true, ['2'] = true, [2] = true, ['current'] = true, ['1'] = true, [1] = true}
|
||||||
|
|
||||||
|
|||||||
77
test/test_neovim_diagnostics.vader
Normal file
77
test/test_neovim_diagnostics.vader
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_use_neovim_diagnostics_api
|
||||||
|
|
||||||
|
function! CollectMessages(buffer)
|
||||||
|
if !has('nvim-0.6')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:messages = []
|
||||||
|
for l:diag in v:lua.vim.diagnostic.get(a:buffer)
|
||||||
|
call add(l:messages, l:diag.message)
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:messages
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
After:
|
||||||
|
unlet! b:other_bufnr
|
||||||
|
delfunction CollectMessages
|
||||||
|
Restore
|
||||||
|
|
||||||
|
Execute(Should only set diagnostics belonging to the given buffer):
|
||||||
|
if has('nvim-0.6')
|
||||||
|
|
||||||
|
let b:other_bufnr = bufnr('/foo/bar/baz', 1)
|
||||||
|
" Make sure we actually get another buffer number, or the test is invalid.
|
||||||
|
AssertNotEqual -1, b:other_bufnr
|
||||||
|
|
||||||
|
let g:ale_use_neovim_diagnostics_api = 1
|
||||||
|
|
||||||
|
call ale#engine#SetResults(bufnr('%'), [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'col': 10,
|
||||||
|
\ 'bufnr': bufnr('%'),
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'linter_name': 'bettercode',
|
||||||
|
\ 'nr': -1,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'text': 'A',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 2,
|
||||||
|
\ 'col': 10,
|
||||||
|
\ 'bufnr': b:other_bufnr,
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'linter_name': 'bettercode',
|
||||||
|
\ 'nr': -1,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'text': 'B',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 3,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'bufnr': bufnr('%'),
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'linter_name': 'bettercode',
|
||||||
|
\ 'nr': -1,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'text': 'C',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 4,
|
||||||
|
\ 'col': 1,
|
||||||
|
\ 'bufnr': b:other_bufnr,
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'linter_name': 'bettercode',
|
||||||
|
\ 'nr': -1,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'text': 'D',
|
||||||
|
\ },
|
||||||
|
\])
|
||||||
|
|
||||||
|
AssertEqual ["A", "C"], CollectMessages(bufnr('%'))
|
||||||
|
|
||||||
|
endif
|
||||||
Reference in New Issue
Block a user