diff options
author | Maria José Solano <majosolano99@gmail.com> | 2024-02-18 18:46:19 -0800 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-02-25 22:08:11 +0000 |
commit | 185752614d1a4906c8f218e4c24c3b52bbe6560e (patch) | |
tree | a64439517eb720779264b114f7ebb60c6a2886b5 /runtime/lua/vim | |
parent | 0fcbda59871ebc5fc91cac7fa430a4a93f6698c2 (diff) | |
download | rneovim-185752614d1a4906c8f218e4c24c3b52bbe6560e.tar.gz rneovim-185752614d1a4906c8f218e4c24c3b52bbe6560e.tar.bz2 rneovim-185752614d1a4906c8f218e4c24c3b52bbe6560e.zip |
refactor(types): fix miscellaneous type warnings
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 11 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/highlighter.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/ui.lua | 9 | ||||
-rw-r--r-- | runtime/lua/vim/version.lua | 19 |
4 files changed, 27 insertions, 14 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index 2aa46ceebd..e2197168f0 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -294,6 +294,7 @@ function M.get_captures_at_pos(bufnr, row, col) for capture, node, metadata in iter do if M.is_in_node_range(node, row, col) then + ---@diagnostic disable-next-line: invisible local c = q._query.captures[capture] -- name of the capture in the query if c ~= nil then table.insert(matches, { capture = c, metadata = metadata, lang = tree:lang() }) @@ -325,6 +326,12 @@ function M.get_captures_at_cursor(winnr) return captures end +--- @class vim.treesitter.GetNodeOpts +--- @field bufnr integer? +--- @field pos { [1]: integer, [2]: integer }? +--- @field lang string? +--- @field ignore_injections boolean? + --- Returns the smallest named node at the given position --- --- NOTE: Calling this on an unparsed tree can yield an invalid node. @@ -335,7 +342,7 @@ end --- vim.treesitter.get_parser(bufnr):parse(range) --- ``` --- ----@param opts table|nil Optional keyword arguments: +---@param opts vim.treesitter.GetNodeOpts? Optional keyword arguments: --- - bufnr integer|nil Buffer number (nil or 0 for current buffer) --- - pos table|nil 0-indexed (row, col) tuple. Defaults to cursor position in the --- current window. Required if {bufnr} is not the current buffer @@ -352,7 +359,7 @@ function M.get_node(opts) bufnr = api.nvim_get_current_buf() end - local row, col + local row, col --- @type integer, integer if opts.pos then assert(#opts.pos == 2, 'Position must be a (row, col) tuple') row, col = opts.pos[1], opts.pos[2] diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 08c4c2a832..99cc9bea09 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -7,7 +7,7 @@ local ns = api.nvim_create_namespace('treesitter/highlighter') ---@alias vim.treesitter.highlighter.Iter fun(end_line: integer|nil): integer, TSNode, TSMetadata ---@class vim.treesitter.highlighter.Query ----@field private _query vim.treesitter.query.Query? +---@field private _query vim.treesitter.Query? ---@field private lang string ---@field private hl_cache table<integer,integer> local TSHighlighterQuery = {} diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua index 157b1461c3..b0e7ca1a35 100644 --- a/runtime/lua/vim/ui.lua +++ b/runtime/lua/vim/ui.lua @@ -20,7 +20,7 @@ local M = {} --- end) --- ``` --- ----@param items table Arbitrary items +---@param items any[] Arbitrary items ---@param opts table Additional options --- - prompt (string|nil) --- Text of the prompt. Defaults to `Select one of:` @@ -32,7 +32,7 @@ local M = {} --- Plugins reimplementing `vim.ui.select` may wish to --- use this to infer the structure or semantics of --- `items`, or the context in which select() was called. ----@param on_choice function ((item|nil, idx|nil) -> ()) +---@param on_choice fun(item: any|nil, idx: integer|nil) --- Called once the user made a choice. --- `idx` is the 1-based index of `item` within `items`. --- `nil` if the user aborted the dialog. @@ -44,7 +44,7 @@ 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 pairs(items) do + for i, item in ipairs(items) do table.insert(choices, string.format('%d: %s', i, format_item(item))) end local choice = vim.fn.inputlist(choices) @@ -66,7 +66,7 @@ end --- end) --- ``` --- ----@param opts table Additional options. See |input()| +---@param opts table? Additional options. See |input()| --- - prompt (string|nil) --- Text of the prompt --- - default (string|nil) @@ -87,6 +87,7 @@ end --- `nil` if the user aborted the dialog. function M.input(opts, on_confirm) vim.validate({ + opts = { opts, 'table', true }, on_confirm = { on_confirm, 'function', false }, }) diff --git a/runtime/lua/vim/version.lua b/runtime/lua/vim/version.lua index 4f52938c6e..58c2a2386d 100644 --- a/runtime/lua/vim/version.lua +++ b/runtime/lua/vim/version.lua @@ -69,6 +69,8 @@ Version.__index = Version --- Compares prerelease strings: per semver, number parts must be must be treated as numbers: --- "pre1.10" is greater than "pre1.2". https://semver.org/#spec-item-11 +---@param prerel1 string? +---@param prerel2 string? local function cmp_prerel(prerel1, prerel2) if not prerel1 or not prerel2 then return prerel1 and -1 or (prerel2 and 1 or 0) @@ -78,8 +80,8 @@ local function cmp_prerel(prerel1, prerel2) local iter1 = prerel1:gmatch('([^0-9]*)(%d*)') local iter2 = prerel2:gmatch('([^0-9]*)(%d*)') while true do - local word1, n1 = iter1() - local word2, n2 = iter2() + local word1, n1 = iter1() --- @type string?, string|number|nil + local word2, n2 = iter2() --- @type string?, string|number|nil if word1 == nil and word2 == nil then -- Done iterating. return 0 end @@ -168,6 +170,7 @@ function M._version(version, strict) -- Adapted from https://github.com/folke/la end if not strict then -- TODO: add more "scrubbing". + --- @cast version string version = version:match('%d[^ ]*') end @@ -298,8 +301,9 @@ function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim local semver = M.parse(version) if semver then - local from = semver - local to = vim.deepcopy(semver, true) + local from = semver --- @type Version? + local to = vim.deepcopy(semver, true) --- @type Version? + ---@diagnostic disable: need-check-nil if mods == '' or mods == '=' then to.patch = to.patch + 1 elseif mods == '<' then @@ -309,9 +313,9 @@ function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim to.patch = to.patch + 1 elseif mods == '>' then from.patch = from.patch + 1 - to = nil ---@diagnostic disable-line: cast-local-type + to = nil elseif mods == '>=' then - to = nil ---@diagnostic disable-line: cast-local-type + to = nil elseif mods == '~' then if #parts >= 2 then to[2] = to[2] + 1 @@ -332,6 +336,7 @@ function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim end end end + ---@diagnostic enable: need-check-nil return setmetatable({ from = from, to = to }, { __index = VersionRange }) end end @@ -445,7 +450,7 @@ setmetatable(M, { --- Returns the current Nvim version. ---@return Version __call = function() - local version = vim.fn.api_info().version + local version = vim.fn.api_info().version ---@type Version -- Workaround: vim.fn.api_info().version reports "prerelease" as a boolean. version.prerelease = version.prerelease and 'dev' or nil return setmetatable(version, Version) |