aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/async.lua31
-rw-r--r--lua/nvim-treesitter/indent.lua2
-rw-r--r--lua/nvim-treesitter/install.lua6
3 files changed, 26 insertions, 13 deletions
diff --git a/lua/nvim-treesitter/async.lua b/lua/nvim-treesitter/async.lua
index e78c0f964..a0a59e4b1 100644
--- a/lua/nvim-treesitter/async.lua
+++ b/lua/nvim-treesitter/async.lua
@@ -1,3 +1,4 @@
+---@meta nvim-treesitter.async vendored file, don't diagnose
local pcall = copcall or pcall
--- @param ... any
@@ -345,8 +346,9 @@ end
--- -- Since uv functions have sync versions. You can just do:
--- local stat = vim.fs_stat('foo.txt')
--- ```
---- @param func function
---- @param ... any
+--- @generic T, R
+--- @param func async fun(...: T...): R...
+--- @param ... T...
--- @return async.Task
function M.arun(func, ...)
local task = Task._new(func)
@@ -354,19 +356,27 @@ function M.arun(func, ...)
return task
end
---- @class async.TaskFun
---- @field package _fun fun(...: any): any
---- @operator call(...): any
+--- @alias async.TaskFun<T, R> fun(...: T...): async.Task
+
+--- @generic T, R
+--- @class async._TaskFun<T, R>
+--- @field package _fun async fun(...: T...): R...
+--- @operator call(...: T...): async.Task
local TaskFun = {}
TaskFun.__index = TaskFun
+--- @generic T, R
+--- @param self async._TaskFun<T, R>
+--- @param ... T...
+--- @return async.Task
function TaskFun:__call(...)
return M.arun(self._fun, ...)
end
--- Create an async function
---- @param fun function
---- @return async.TaskFun
+--- @generic T, R
+--- @param fun async fun(...: T...): R...
+--- @return async.TaskFun<T, R>
function M.async(fun)
return setmetatable({ _fun = fun }, TaskFun)
end
@@ -430,9 +440,10 @@ local function await_cbfun(argc, fun, ...)
end)
end
---- @param taskfun async.TaskFun
---- @param ... any
---- @return any ...
+--- @generic T, R
+--- @param taskfun async.TaskFun<T, R>
+--- @param ... T...
+--- @return R...
local function await_taskfun(taskfun, ...)
return taskfun._fun(...)
end
diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua
index 6f8e4d8ff..ee513c351 100644
--- a/lua/nvim-treesitter/indent.lua
+++ b/lua/nvim-treesitter/indent.lua
@@ -97,7 +97,7 @@ local get_indents = memoize(function(bufnr, root, lang)
return map
end
for id, node, metadata in query:iter_captures(root, bufnr) do
- if query.captures[id]:sub(1, 1) ~= '_' then
+ if assert(query.captures[id]):sub(1, 1) ~= '_' then
map[query.captures[id]][node:id()] = metadata or {}
end
end
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index 893f95361..71d5a3c76 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -85,6 +85,7 @@ local function join(max_jobs, tasks)
end
for i = 1, max_jobs do
+ assert(tasks[i])
tasks[i]():await(cb)
end
end)
@@ -155,7 +156,8 @@ end
---@param ... string
---@return string
function M.get_package_path(...)
- return fs.joinpath(fn.fnamemodify(debug.getinfo(1, 'S').source:sub(2), ':p:h:h:h'), ...)
+ local info = assert(debug.getinfo(1, 'S'))
+ return fs.joinpath(fn.fnamemodify(info.source:sub(2), ':p:h:h:h'), ...)
end
---@param lang string
@@ -487,8 +489,8 @@ end
--- Reload the parser table and user modifications in case of update
local function reload_parsers()
- ---@diagnostic disable-next-line:no-unknown
package.loaded['nvim-treesitter.parsers'] = nil
+ ---@diagnostic disable-next-line:duplicate-require
parsers = require('nvim-treesitter.parsers')
vim.api.nvim_exec_autocmds('User', { pattern = 'TSUpdate' })
end