mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
fix: another round of type annotation fixes
This commit is contained in:
parent
0ab4d36254
commit
1d4ba8c1ed
@ -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
|
||||
|
||||
|
@ -1908,7 +1908,7 @@ local function match_from_hashbang(contents, path, dispatch_extension)
|
||||
end
|
||||
|
||||
for k, v in pairs(patterns_hashbang) do
|
||||
local ft = type(v) == 'table' and v[1] or v
|
||||
local ft = type(v) == 'table' and v[1] or v --[[@as string]]
|
||||
local opts = type(v) == 'table' and v[2] or {}
|
||||
if opts.vim_regex and matchregex(name, k) or name:find(k) then
|
||||
return ft
|
||||
@ -2080,6 +2080,7 @@ local function match_from_text(contents, path)
|
||||
return ft
|
||||
end
|
||||
else
|
||||
--- @cast k string
|
||||
local opts = type(v) == 'table' and v[2] or {}
|
||||
if opts.start_lnum and opts.end_lnum then
|
||||
assert(
|
||||
|
@ -48,7 +48,7 @@ function M.to_lpeg(pattern)
|
||||
end
|
||||
|
||||
-- luacheck: push ignore s
|
||||
local function cut(s, idx, match)
|
||||
local function cut(_s, idx, match)
|
||||
return idx, match
|
||||
end
|
||||
-- luacheck: pop
|
||||
|
@ -782,7 +782,8 @@ end
|
||||
|
||||
do
|
||||
--- @alias vim.validate.Validator
|
||||
--- | type|'callable'
|
||||
--- | type
|
||||
--- | 'callable'
|
||||
--- | (type|'callable')[]
|
||||
--- | fun(v:any):boolean, string?
|
||||
|
||||
@ -1170,11 +1171,13 @@ function vim._defer_deprecated_module(old_name, new_name)
|
||||
---@param k string
|
||||
__index = function(_, k)
|
||||
vim.deprecate(old_name, new_name, '2.0.0', nil, false)
|
||||
--- @diagnostic disable-next-line:no-unknown
|
||||
local target = require(new_name)
|
||||
return target[k]
|
||||
end,
|
||||
__call = function(self)
|
||||
vim.deprecate(old_name, new_name, '2.0.0', nil, false)
|
||||
--- @diagnostic disable-next-line:no-unknown
|
||||
local target = require(new_name)
|
||||
return target(self)
|
||||
end,
|
||||
@ -1217,11 +1220,14 @@ local state_restore_order = { 'bo', 'wo', 'go', 'env' }
|
||||
--- @param context vim.context.mods
|
||||
--- @return vim.context.state
|
||||
local get_context_state = function(context)
|
||||
--- @type vim.context.state
|
||||
local res = { bo = {}, env = {}, go = {}, wo = {} }
|
||||
|
||||
-- Use specific order from possibly most to least intrusive
|
||||
for _, scope in ipairs(scope_order) do
|
||||
for name, _ in pairs(context[scope] or {}) do
|
||||
for name, _ in
|
||||
pairs(context[scope] or {} --[[@as table<string,any>]])
|
||||
do
|
||||
local sc = scope == 'o' and scope_map[vim.api.nvim_get_option_info2(name, {}).scope] or scope
|
||||
|
||||
-- Do not override already set state and fall back to `vim.NIL` for
|
||||
@ -1315,7 +1321,10 @@ function vim._with(context, f)
|
||||
-- Apply some parts of the context in specific order
|
||||
-- NOTE: triggers `OptionSet` event
|
||||
for _, scope in ipairs(scope_order) do
|
||||
for name, context_value in pairs(context[scope] or {}) do
|
||||
for name, context_value in
|
||||
pairs(context[scope] or {} --[[@as table<string,any>]])
|
||||
do
|
||||
--- @diagnostic disable-next-line:no-unknown
|
||||
vim[scope][name] = context_value
|
||||
end
|
||||
end
|
||||
@ -1326,7 +1335,10 @@ function vim._with(context, f)
|
||||
-- Restore relevant cached values in specific order, global scope last
|
||||
-- NOTE: triggers `OptionSet` event
|
||||
for _, scope in ipairs(state_restore_order) do
|
||||
for name, cached_value in pairs(state[scope]) do
|
||||
for name, cached_value in
|
||||
pairs(state[scope] --[[@as table<string,any>]])
|
||||
do
|
||||
--- @diagnostic disable-next-line:no-unknown
|
||||
vim[scope][name] = cached_value
|
||||
end
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ function M.query(caps, cb)
|
||||
local k, rest = resp:match('^\027P1%+r(%x+)(.*)$')
|
||||
if k and rest then
|
||||
local cap = vim.text.hexdecode(k)
|
||||
if not pending[cap] then
|
||||
if not cap or not pending[cap] then
|
||||
-- Received a response for a capability we didn't request. This can happen if there are
|
||||
-- multiple concurrent XTGETTCAP requests
|
||||
return
|
||||
|
@ -165,7 +165,7 @@ function M.get_node_range(node_or_range)
|
||||
if type(node_or_range) == 'table' then
|
||||
return unpack(node_or_range)
|
||||
else
|
||||
return node_or_range:range()
|
||||
return node_or_range:range(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,9 @@ function M.select(items, opts, on_choice)
|
||||
opts = opts or {}
|
||||
local choices = { opts.prompt or 'Select one of:' }
|
||||
local format_item = opts.format_item or tostring
|
||||
for i, item in ipairs(items) do
|
||||
for i, item in
|
||||
ipairs(items --[[@as any[] ]])
|
||||
do
|
||||
table.insert(choices, string.format('%d: %s', i, format_item(item)))
|
||||
end
|
||||
local choice = vim.fn.inputlist(choices)
|
||||
@ -204,7 +206,9 @@ function M._get_urls()
|
||||
if vim.treesitter.node_contains(node, range) then
|
||||
local url = metadata[id] and metadata[id].url
|
||||
if url and match[url] then
|
||||
for _, n in ipairs(match[url]) do
|
||||
for _, n in
|
||||
ipairs(match[url] --[[@as TSNode[] ]])
|
||||
do
|
||||
urls[#urls + 1] =
|
||||
vim.treesitter.get_node_text(n, bufnr, { metadata = metadata[url] })
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user