mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	fix: another round of type annotation fixes
This commit is contained in:
		
				
					committed by
					
						
						Lewis Russell
					
				
			
			
				
	
			
			
			
						parent
						
							0ab4d36254
						
					
				
				
					commit
					1d4ba8c1ed
				
			@@ -282,6 +282,11 @@ M.severity = {
 | 
				
			|||||||
  [2] = 'WARN',
 | 
					  [2] = 'WARN',
 | 
				
			||||||
  [3] = 'INFO',
 | 
					  [3] = 'INFO',
 | 
				
			||||||
  [4] = 'HINT',
 | 
					  [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
 | 
					--- @alias vim.diagnostic.SeverityInt 1|2|3|4
 | 
				
			||||||
@@ -289,12 +294,6 @@ M.severity = {
 | 
				
			|||||||
--- See |diagnostic-severity| and |vim.diagnostic.get()|
 | 
					--- 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}
 | 
					--- @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
 | 
					--- @type vim.diagnostic.Opts
 | 
				
			||||||
local global_diagnostic_options = {
 | 
					local global_diagnostic_options = {
 | 
				
			||||||
  signs = true,
 | 
					  signs = true,
 | 
				
			||||||
@@ -891,14 +890,14 @@ local function next_diagnostic(search_forward, opts)
 | 
				
			|||||||
  if opts.win_id then
 | 
					  if opts.win_id then
 | 
				
			||||||
    vim.deprecate('opts.win_id', 'opts.winid', '0.13')
 | 
					    vim.deprecate('opts.win_id', 'opts.winid', '0.13')
 | 
				
			||||||
    opts.winid = opts.win_id
 | 
					    opts.winid = opts.win_id
 | 
				
			||||||
    opts.win_id = nil
 | 
					    opts.win_id = nil --- @diagnostic disable-line
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- Support deprecated cursor_position alias
 | 
					  -- Support deprecated cursor_position alias
 | 
				
			||||||
  if opts.cursor_position then
 | 
					  if opts.cursor_position then
 | 
				
			||||||
    vim.deprecate('opts.cursor_position', 'opts.pos', '0.13')
 | 
					    vim.deprecate('opts.cursor_position', 'opts.pos', '0.13')
 | 
				
			||||||
    opts.pos = opts.cursor_position
 | 
					    opts.pos = opts.cursor_position
 | 
				
			||||||
    opts.cursor_position = nil
 | 
					    opts.cursor_position = nil --- @diagnostic disable-line
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local winid = opts.winid or api.nvim_get_current_win()
 | 
					  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
 | 
					  if opts.win_id then
 | 
				
			||||||
    vim.deprecate('opts.win_id', 'opts.winid', '0.13')
 | 
					    vim.deprecate('opts.win_id', 'opts.winid', '0.13')
 | 
				
			||||||
    opts.winid = opts.win_id
 | 
					    opts.winid = opts.win_id
 | 
				
			||||||
    opts.win_id = nil
 | 
					    opts.win_id = nil --- @diagnostic disable-line
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local winid = opts.winid or api.nvim_get_current_win()
 | 
					  local winid = opts.winid or api.nvim_get_current_win()
 | 
				
			||||||
@@ -992,8 +991,9 @@ local function goto_diagnostic(diagnostic, opts)
 | 
				
			|||||||
    vim.cmd('normal! zv')
 | 
					    vim.cmd('normal! zv')
 | 
				
			||||||
  end)
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if opts.float then
 | 
					  local float_opts = opts.float
 | 
				
			||||||
    local float_opts = type(opts.float) == 'table' and opts.float or {}
 | 
					  if float_opts then
 | 
				
			||||||
 | 
					    float_opts = type(float_opts) == 'table' and float_opts or {}
 | 
				
			||||||
    vim.schedule(function()
 | 
					    vim.schedule(function()
 | 
				
			||||||
      M.open_float(vim.tbl_extend('keep', float_opts, {
 | 
					      M.open_float(vim.tbl_extend('keep', float_opts, {
 | 
				
			||||||
        bufnr = api.nvim_win_get_buf(winid),
 | 
					        bufnr = api.nvim_win_get_buf(winid),
 | 
				
			||||||
@@ -1317,7 +1317,7 @@ function M.jump(opts)
 | 
				
			|||||||
  if opts.cursor_position then
 | 
					  if opts.cursor_position then
 | 
				
			||||||
    vim.deprecate('opts.cursor_position', 'opts.pos', '0.13')
 | 
					    vim.deprecate('opts.cursor_position', 'opts.pos', '0.13')
 | 
				
			||||||
    opts.pos = opts.cursor_position
 | 
					    opts.pos = opts.cursor_position
 | 
				
			||||||
    opts.cursor_position = nil
 | 
					    opts.cursor_position = nil --- @diagnostic disable-line
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local diag = nil
 | 
					  local diag = nil
 | 
				
			||||||
@@ -1488,14 +1488,9 @@ M.handlers.underline = {
 | 
				
			|||||||
    local get_priority = severity_to_extmark_priority(vim.hl.priorities.diagnostics, opts)
 | 
					    local get_priority = severity_to_extmark_priority(vim.hl.priorities.diagnostics, opts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for _, diagnostic in ipairs(diagnostics) do
 | 
					    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)]
 | 
					      local higroup = underline_highlight_map[assert(diagnostic.severity)]
 | 
				
			||||||
 | 
					        or underline_highlight_map[vim.diagnostic.severity.ERROR]
 | 
				
			||||||
      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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if diagnostic._tags then
 | 
					      if diagnostic._tags then
 | 
				
			||||||
        -- TODO(lewis6991): we should be able to stack these.
 | 
					        -- 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
 | 
					  enable = enable == nil and true or enable
 | 
				
			||||||
  local bufnr = filter.bufnr
 | 
					  local bufnr = filter.bufnr
 | 
				
			||||||
 | 
					  local ns_id = filter.ns_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if bufnr == nil then
 | 
					  if not bufnr then
 | 
				
			||||||
    if filter.ns_id == nil then
 | 
					    if not ns_id then
 | 
				
			||||||
      diagnostic_disabled = (
 | 
					      diagnostic_disabled = (
 | 
				
			||||||
        enable
 | 
					        enable
 | 
				
			||||||
          -- Enable everything by setting diagnostic_disabled to an empty table.
 | 
					          -- Enable everything by setting diagnostic_disabled to an empty table.
 | 
				
			||||||
@@ -2131,12 +2127,12 @@ function M.enable(enable, filter)
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      local ns = M.get_namespace(filter.ns_id)
 | 
					      local ns = M.get_namespace(ns_id)
 | 
				
			||||||
      ns.disabled = not enable
 | 
					      ns.disabled = not enable
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    bufnr = get_bufnr(bufnr)
 | 
					    bufnr = get_bufnr(bufnr)
 | 
				
			||||||
    if filter.ns_id == nil then
 | 
					    if not ns_id then
 | 
				
			||||||
      diagnostic_disabled[bufnr] = (not enable) and true or nil
 | 
					      diagnostic_disabled[bufnr] = (not enable) and true or nil
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      if type(diagnostic_disabled[bufnr]) ~= 'table' then
 | 
					      if type(diagnostic_disabled[bufnr]) ~= 'table' then
 | 
				
			||||||
@@ -2146,14 +2142,14 @@ function M.enable(enable, filter)
 | 
				
			|||||||
          diagnostic_disabled[bufnr] = {}
 | 
					          diagnostic_disabled[bufnr] = {}
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      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
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if enable then
 | 
					  if enable then
 | 
				
			||||||
    M.show(filter.ns_id, bufnr)
 | 
					    M.show(ns_id, bufnr)
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    M.hide(filter.ns_id, bufnr)
 | 
					    M.hide(ns_id, bufnr)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1908,7 +1908,7 @@ local function match_from_hashbang(contents, path, dispatch_extension)
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for k, v in pairs(patterns_hashbang) do
 | 
					  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 {}
 | 
					    local opts = type(v) == 'table' and v[2] or {}
 | 
				
			||||||
    if opts.vim_regex and matchregex(name, k) or name:find(k) then
 | 
					    if opts.vim_regex and matchregex(name, k) or name:find(k) then
 | 
				
			||||||
      return ft
 | 
					      return ft
 | 
				
			||||||
@@ -2080,6 +2080,7 @@ local function match_from_text(contents, path)
 | 
				
			|||||||
        return ft
 | 
					        return ft
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
 | 
					      --- @cast k string
 | 
				
			||||||
      local opts = type(v) == 'table' and v[2] or {}
 | 
					      local opts = type(v) == 'table' and v[2] or {}
 | 
				
			||||||
      if opts.start_lnum and opts.end_lnum then
 | 
					      if opts.start_lnum and opts.end_lnum then
 | 
				
			||||||
        assert(
 | 
					        assert(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,7 +48,7 @@ function M.to_lpeg(pattern)
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- luacheck: push ignore s
 | 
					  -- luacheck: push ignore s
 | 
				
			||||||
  local function cut(s, idx, match)
 | 
					  local function cut(_s, idx, match)
 | 
				
			||||||
    return idx, match
 | 
					    return idx, match
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  -- luacheck: pop
 | 
					  -- luacheck: pop
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -782,7 +782,8 @@ end
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
do
 | 
					do
 | 
				
			||||||
  --- @alias vim.validate.Validator
 | 
					  --- @alias vim.validate.Validator
 | 
				
			||||||
  --- | type|'callable'
 | 
					  --- | type
 | 
				
			||||||
 | 
					  --- | 'callable'
 | 
				
			||||||
  --- | (type|'callable')[]
 | 
					  --- | (type|'callable')[]
 | 
				
			||||||
  --- | fun(v:any):boolean, string?
 | 
					  --- | fun(v:any):boolean, string?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1170,11 +1171,13 @@ function vim._defer_deprecated_module(old_name, new_name)
 | 
				
			|||||||
    ---@param k string
 | 
					    ---@param k string
 | 
				
			||||||
    __index = function(_, k)
 | 
					    __index = function(_, k)
 | 
				
			||||||
      vim.deprecate(old_name, new_name, '2.0.0', nil, false)
 | 
					      vim.deprecate(old_name, new_name, '2.0.0', nil, false)
 | 
				
			||||||
 | 
					      --- @diagnostic disable-next-line:no-unknown
 | 
				
			||||||
      local target = require(new_name)
 | 
					      local target = require(new_name)
 | 
				
			||||||
      return target[k]
 | 
					      return target[k]
 | 
				
			||||||
    end,
 | 
					    end,
 | 
				
			||||||
    __call = function(self)
 | 
					    __call = function(self)
 | 
				
			||||||
      vim.deprecate(old_name, new_name, '2.0.0', nil, false)
 | 
					      vim.deprecate(old_name, new_name, '2.0.0', nil, false)
 | 
				
			||||||
 | 
					      --- @diagnostic disable-next-line:no-unknown
 | 
				
			||||||
      local target = require(new_name)
 | 
					      local target = require(new_name)
 | 
				
			||||||
      return target(self)
 | 
					      return target(self)
 | 
				
			||||||
    end,
 | 
					    end,
 | 
				
			||||||
@@ -1217,11 +1220,14 @@ local state_restore_order = { 'bo', 'wo', 'go', 'env' }
 | 
				
			|||||||
--- @param context vim.context.mods
 | 
					--- @param context vim.context.mods
 | 
				
			||||||
--- @return vim.context.state
 | 
					--- @return vim.context.state
 | 
				
			||||||
local get_context_state = function(context)
 | 
					local get_context_state = function(context)
 | 
				
			||||||
 | 
					  --- @type vim.context.state
 | 
				
			||||||
  local res = { bo = {}, env = {}, go = {}, wo = {} }
 | 
					  local res = { bo = {}, env = {}, go = {}, wo = {} }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- Use specific order from possibly most to least intrusive
 | 
					  -- Use specific order from possibly most to least intrusive
 | 
				
			||||||
  for _, scope in ipairs(scope_order) do
 | 
					  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
 | 
					      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
 | 
					      -- 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
 | 
					    -- Apply some parts of the context in specific order
 | 
				
			||||||
    -- NOTE: triggers `OptionSet` event
 | 
					    -- NOTE: triggers `OptionSet` event
 | 
				
			||||||
    for _, scope in ipairs(scope_order) do
 | 
					    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
 | 
					        vim[scope][name] = context_value
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
@@ -1326,7 +1335,10 @@ function vim._with(context, f)
 | 
				
			|||||||
    -- Restore relevant cached values in specific order, global scope last
 | 
					    -- Restore relevant cached values in specific order, global scope last
 | 
				
			||||||
    -- NOTE: triggers `OptionSet` event
 | 
					    -- NOTE: triggers `OptionSet` event
 | 
				
			||||||
    for _, scope in ipairs(state_restore_order) do
 | 
					    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
 | 
					        vim[scope][name] = cached_value
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,7 @@ function M.query(caps, cb)
 | 
				
			|||||||
      local k, rest = resp:match('^\027P1%+r(%x+)(.*)$')
 | 
					      local k, rest = resp:match('^\027P1%+r(%x+)(.*)$')
 | 
				
			||||||
      if k and rest then
 | 
					      if k and rest then
 | 
				
			||||||
        local cap = vim.text.hexdecode(k)
 | 
					        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
 | 
					          -- Received a response for a capability we didn't request. This can happen if there are
 | 
				
			||||||
          -- multiple concurrent XTGETTCAP requests
 | 
					          -- multiple concurrent XTGETTCAP requests
 | 
				
			||||||
          return
 | 
					          return
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -165,7 +165,7 @@ function M.get_node_range(node_or_range)
 | 
				
			|||||||
  if type(node_or_range) == 'table' then
 | 
					  if type(node_or_range) == 'table' then
 | 
				
			||||||
    return unpack(node_or_range)
 | 
					    return unpack(node_or_range)
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    return node_or_range:range()
 | 
					    return node_or_range:range(false)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,7 +43,9 @@ function M.select(items, opts, on_choice)
 | 
				
			|||||||
  opts = opts or {}
 | 
					  opts = opts or {}
 | 
				
			||||||
  local choices = { opts.prompt or 'Select one of:' }
 | 
					  local choices = { opts.prompt or 'Select one of:' }
 | 
				
			||||||
  local format_item = opts.format_item or tostring
 | 
					  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)))
 | 
					    table.insert(choices, string.format('%d: %s', i, format_item(item)))
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  local choice = vim.fn.inputlist(choices)
 | 
					  local choice = vim.fn.inputlist(choices)
 | 
				
			||||||
@@ -204,7 +206,9 @@ function M._get_urls()
 | 
				
			|||||||
            if vim.treesitter.node_contains(node, range) then
 | 
					            if vim.treesitter.node_contains(node, range) then
 | 
				
			||||||
              local url = metadata[id] and metadata[id].url
 | 
					              local url = metadata[id] and metadata[id].url
 | 
				
			||||||
              if url and match[url] then
 | 
					              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] =
 | 
					                  urls[#urls + 1] =
 | 
				
			||||||
                    vim.treesitter.get_node_text(n, bufnr, { metadata = metadata[url] })
 | 
					                    vim.treesitter.get_node_text(n, bufnr, { metadata = metadata[url] })
 | 
				
			||||||
                end
 | 
					                end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user