aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/diagnostic.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-10-31 11:28:02 +0000
committerLewis Russell <me@lewisr.dev>2024-10-31 11:55:23 +0000
commit1d4ba8c1edba064421b34c1197c3470a09798218 (patch)
treedf78030ef12f7c275b6c4a888c96032db9b0dfd4 /runtime/lua/vim/diagnostic.lua
parent0ab4d362549399c79f662ca635839dafe6c974db (diff)
downloadrneovim-1d4ba8c1edba064421b34c1197c3470a09798218.tar.gz
rneovim-1d4ba8c1edba064421b34c1197c3470a09798218.tar.bz2
rneovim-1d4ba8c1edba064421b34c1197c3470a09798218.zip
fix: another round of type annotation fixes
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r--runtime/lua/vim/diagnostic.lua48
1 files changed, 22 insertions, 26 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index 299f34c921..4fb8c6a686 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -282,6 +282,11 @@ M.severity = {
[2] = 'WARN',
[3] = 'INFO',
[4] = 'HINT',
+ --- Mappings from qflist/loclist error types to severities
+ E = 1,
+ W = 2,
+ I = 3,
+ N = 4,
}
--- @alias vim.diagnostic.SeverityInt 1|2|3|4
@@ -289,12 +294,6 @@ M.severity = {
--- See |diagnostic-severity| and |vim.diagnostic.get()|
--- @alias vim.diagnostic.SeverityFilter vim.diagnostic.Severity|vim.diagnostic.Severity[]|{min:vim.diagnostic.Severity,max:vim.diagnostic.Severity}
--- Mappings from qflist/loclist error types to severities
-M.severity.E = M.severity.ERROR
-M.severity.W = M.severity.WARN
-M.severity.I = M.severity.INFO
-M.severity.N = M.severity.HINT
-
--- @type vim.diagnostic.Opts
local global_diagnostic_options = {
signs = true,
@@ -891,14 +890,14 @@ local function next_diagnostic(search_forward, opts)
if opts.win_id then
vim.deprecate('opts.win_id', 'opts.winid', '0.13')
opts.winid = opts.win_id
- opts.win_id = nil
+ opts.win_id = nil --- @diagnostic disable-line
end
-- Support deprecated cursor_position alias
if opts.cursor_position then
vim.deprecate('opts.cursor_position', 'opts.pos', '0.13')
opts.pos = opts.cursor_position
- opts.cursor_position = nil
+ opts.cursor_position = nil --- @diagnostic disable-line
end
local winid = opts.winid or api.nvim_get_current_win()
@@ -979,7 +978,7 @@ local function goto_diagnostic(diagnostic, opts)
if opts.win_id then
vim.deprecate('opts.win_id', 'opts.winid', '0.13')
opts.winid = opts.win_id
- opts.win_id = nil
+ opts.win_id = nil --- @diagnostic disable-line
end
local winid = opts.winid or api.nvim_get_current_win()
@@ -992,8 +991,9 @@ local function goto_diagnostic(diagnostic, opts)
vim.cmd('normal! zv')
end)
- if opts.float then
- local float_opts = type(opts.float) == 'table' and opts.float or {}
+ local float_opts = opts.float
+ if float_opts then
+ float_opts = type(float_opts) == 'table' and float_opts or {}
vim.schedule(function()
M.open_float(vim.tbl_extend('keep', float_opts, {
bufnr = api.nvim_win_get_buf(winid),
@@ -1317,7 +1317,7 @@ function M.jump(opts)
if opts.cursor_position then
vim.deprecate('opts.cursor_position', 'opts.pos', '0.13')
opts.pos = opts.cursor_position
- opts.cursor_position = nil
+ opts.cursor_position = nil --- @diagnostic disable-line
end
local diag = nil
@@ -1488,14 +1488,9 @@ M.handlers.underline = {
local get_priority = severity_to_extmark_priority(vim.hl.priorities.diagnostics, opts)
for _, diagnostic in ipairs(diagnostics) do
- --- @type string?
+ -- Default to error if we don't have a highlight associated
local higroup = underline_highlight_map[assert(diagnostic.severity)]
-
- if higroup == nil then
- -- Default to error if we don't have a highlight associated
- -- TODO(lewis6991): this is always nil since underline_highlight_map only has integer keys
- higroup = underline_highlight_map.Error
- end
+ or underline_highlight_map[vim.diagnostic.severity.ERROR]
if diagnostic._tags then
-- TODO(lewis6991): we should be able to stack these.
@@ -2115,9 +2110,10 @@ function M.enable(enable, filter)
enable = enable == nil and true or enable
local bufnr = filter.bufnr
+ local ns_id = filter.ns_id
- if bufnr == nil then
- if filter.ns_id == nil then
+ if not bufnr then
+ if not ns_id then
diagnostic_disabled = (
enable
-- Enable everything by setting diagnostic_disabled to an empty table.
@@ -2131,12 +2127,12 @@ function M.enable(enable, filter)
})
)
else
- local ns = M.get_namespace(filter.ns_id)
+ local ns = M.get_namespace(ns_id)
ns.disabled = not enable
end
else
bufnr = get_bufnr(bufnr)
- if filter.ns_id == nil then
+ if not ns_id then
diagnostic_disabled[bufnr] = (not enable) and true or nil
else
if type(diagnostic_disabled[bufnr]) ~= 'table' then
@@ -2146,14 +2142,14 @@ function M.enable(enable, filter)
diagnostic_disabled[bufnr] = {}
end
end
- diagnostic_disabled[bufnr][filter.ns_id] = (not enable) and true or nil
+ diagnostic_disabled[bufnr][ns_id] = (not enable) and true or nil
end
end
if enable then
- M.show(filter.ns_id, bufnr)
+ M.show(ns_id, bufnr)
else
- M.hide(filter.ns_id, bufnr)
+ M.hide(ns_id, bufnr)
end
end