mirror of
https://github.com/neovim/neovim.git
synced 2025-12-07 15:14:04 +00:00
lsp: Add severity_limit for other diagnostics features (#13528)
* lsp: Add severity_limit for other diagnostics * docs and tests * fix: lint * Add to other types * fix: lint
This commit is contained in:
@@ -12,41 +12,41 @@ describe('vim.lsp.diagnostic', function()
|
||||
clear()
|
||||
|
||||
exec_lua [[
|
||||
require('vim.lsp')
|
||||
require('vim.lsp')
|
||||
|
||||
make_range = function(x1, y1, x2, y2)
|
||||
return { start = { line = x1, character = y1 }, ['end'] = { line = x2, character = y2 } }
|
||||
end
|
||||
make_range = function(x1, y1, x2, y2)
|
||||
return { start = { line = x1, character = y1 }, ['end'] = { line = x2, character = y2 } }
|
||||
end
|
||||
|
||||
make_error = function(msg, x1, y1, x2, y2)
|
||||
return {
|
||||
range = make_range(x1, y1, x2, y2),
|
||||
message = msg,
|
||||
severity = 1,
|
||||
}
|
||||
end
|
||||
make_error = function(msg, x1, y1, x2, y2)
|
||||
return {
|
||||
range = make_range(x1, y1, x2, y2),
|
||||
message = msg,
|
||||
severity = 1,
|
||||
}
|
||||
end
|
||||
|
||||
make_warning = function(msg, x1, y1, x2, y2)
|
||||
return {
|
||||
range = make_range(x1, y1, x2, y2),
|
||||
message = msg,
|
||||
severity = 2,
|
||||
}
|
||||
end
|
||||
make_warning = function(msg, x1, y1, x2, y2)
|
||||
return {
|
||||
range = make_range(x1, y1, x2, y2),
|
||||
message = msg,
|
||||
severity = 2,
|
||||
}
|
||||
end
|
||||
|
||||
make_information = function(msg, x1, y1, x2, y2)
|
||||
return {
|
||||
range = make_range(x1, y1, x2, y2),
|
||||
message = msg,
|
||||
severity = 3,
|
||||
}
|
||||
end
|
||||
make_information = function(msg, x1, y1, x2, y2)
|
||||
return {
|
||||
range = make_range(x1, y1, x2, y2),
|
||||
message = msg,
|
||||
severity = 3,
|
||||
}
|
||||
end
|
||||
|
||||
count_of_extmarks_for_client = function(bufnr, client_id)
|
||||
return #vim.api.nvim_buf_get_extmarks(
|
||||
bufnr, vim.lsp.diagnostic._get_diagnostic_namespace(client_id), 0, -1, {}
|
||||
)
|
||||
end
|
||||
count_of_extmarks_for_client = function(bufnr, client_id)
|
||||
return #vim.api.nvim_buf_get_extmarks(
|
||||
bufnr, vim.lsp.diagnostic._get_diagnostic_namespace(client_id), 0, -1, {}
|
||||
)
|
||||
end
|
||||
]]
|
||||
|
||||
fake_uri = "file://fake/uri"
|
||||
@@ -640,6 +640,36 @@ describe('vim.lsp.diagnostic', function()
|
||||
|
||||
eq(expected_spacing, #spacing)
|
||||
end)
|
||||
|
||||
it('allows filtering via severity limit', function()
|
||||
local get_extmark_count_with_severity = function(severity_limit)
|
||||
return exec_lua([[
|
||||
PublishDiagnostics = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||
underline = false,
|
||||
virtual_text = {
|
||||
severity_limit = ...
|
||||
},
|
||||
})
|
||||
|
||||
PublishDiagnostics(nil, nil, {
|
||||
uri = fake_uri,
|
||||
diagnostics = {
|
||||
make_warning('Delayed Diagnostic', 4, 4, 4, 4),
|
||||
}
|
||||
}, 1
|
||||
)
|
||||
|
||||
return count_of_extmarks_for_client(diagnostic_bufnr, 1)
|
||||
]], severity_limit)
|
||||
end
|
||||
|
||||
-- No messages with Error or higher
|
||||
eq(0, get_extmark_count_with_severity("Error"))
|
||||
|
||||
-- But now we don't filter it
|
||||
eq(1, get_extmark_count_with_severity("Warning"))
|
||||
eq(1, get_extmark_count_with_severity("Hint"))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('lsp.util.show_line_diagnostics', function()
|
||||
|
||||
Reference in New Issue
Block a user