fix: resolve all remaining LuaLS diagnostics

This commit is contained in:
Lewis Russell
2025-01-24 13:01:25 +00:00
committed by Lewis Russell
parent 83479b95ab
commit 6aa42e8f92
41 changed files with 177 additions and 104 deletions

View File

@@ -20,9 +20,15 @@ error('Cannot require a meta file')
---@class (exact) TSQueryInfo
---@field captures string[]
---@field patterns table<integer, (integer|string)[][]>
---
---@class TSLangInfo
---@field fields string[]
---@field symbols table<string,boolean>
---@field _wasm boolean
---@field _abi_version integer
--- @param lang string
--- @return table
--- @return TSLangInfo
vim._ts_inspect_language = function(lang) end
---@return integer

View File

@@ -104,6 +104,7 @@ function TSNode:end_() end
--- - end column
--- - end byte (if {include_bytes} is `true`)
--- @param include_bytes boolean?
--- @return integer, integer, integer, integer
function TSNode:range(include_bytes) end
--- @nodoc

View File

@@ -138,7 +138,9 @@ local function lint_match(buf, match, query, lang_context, diagnostics)
-- perform language-independent checks only for first lang
if lang_context.is_first_lang and cap_id == 'error' then
local node_text = vim.treesitter.get_node_text(node, buf):gsub('\n', ' ')
add_lint_for_node(diagnostics, { node:range() }, 'Syntax error: ' .. node_text)
---@diagnostic disable-next-line: missing-fields LuaLS varargs bug
local range = { node:range() } --- @type Range4
add_lint_for_node(diagnostics, range, 'Syntax error: ' .. node_text)
end
-- other checks rely on Neovim parser introspection

View File

@@ -137,14 +137,6 @@ end
local decor_ns = api.nvim_create_namespace('nvim.treesitter.dev')
---@param range Range4
---@return string
local function range_to_string(range)
---@type integer, integer, integer, integer
local row, col, end_row, end_col = unpack(range)
return string.format('[%d, %d] - [%d, %d]', row, col, end_row, end_col)
end
---@param w integer
---@return boolean closed Whether the window was closed.
local function close_win(w)
@@ -227,7 +219,7 @@ function TSTreeView:draw(bufnr)
local lang_hl_marks = {} ---@type table[]
for i, item in self:iter() do
local range_str = range_to_string({ item.node:range() })
local range_str = ('[%d, %d] - [%d, %d]'):format(item.node:range())
local lang_str = self.opts.lang and string.format(' %s', item.lang) or ''
local text ---@type string

View File

@@ -175,7 +175,7 @@ end
--- (`"`).
---
---@param lang string Language
---@return table
---@return TSLangInfo
function M.inspect(lang)
M.add(lang)
return vim._ts_inspect_language(lang)

View File

@@ -123,7 +123,7 @@ function LanguageTree.new(source, lang, opts)
local injections = opts.injections or {}
--- @type vim.treesitter.LanguageTree
--- @class vim.treesitter.LanguageTree
local self = {
_source = source,
_lang = lang,
@@ -190,7 +190,7 @@ end
---Measure execution time of a function
---@generic R1, R2, R3
---@param f fun(): R1, R2, R2
---@param f fun(): R1, R2, R3
---@return number, R1, R2, R3
local function tcall(f, ...)
local start = vim.uv.hrtime()
@@ -198,6 +198,7 @@ local function tcall(f, ...)
local r = { f(...) }
--- @type number
local duration = (vim.uv.hrtime() - start) / 1000000
--- @diagnostic disable-next-line: redundant-return-value
return duration, unpack(r)
end
@@ -550,14 +551,14 @@ function LanguageTree:_parse(range, timeout)
local no_regions_parsed = 0
local query_time = 0
local total_parse_time = 0
local is_finished --- @type boolean
-- At least 1 region is invalid
if not self:is_valid(true) then
local is_finished
changes, no_regions_parsed, total_parse_time, is_finished = self:_parse_regions(range, timeout)
timeout = timeout and math.max(timeout - total_parse_time, 0)
if not is_finished then
return self._trees, is_finished
return self._trees, false
end
-- Need to run injections when we parsed something
if no_regions_parsed > 0 then
@@ -740,6 +741,7 @@ function LanguageTree:set_included_regions(new_regions)
if type(range) == 'table' and #range == 4 then
region[i] = Range.add_bytes(self._source, range --[[@as Range4]])
elseif type(range) == 'userdata' then
--- @diagnostic disable-next-line: missing-fields LuaLS varargs bug
region[i] = { range:range(true) }
end
end

View File

@@ -262,6 +262,7 @@ local explicit_queries = setmetatable({}, {
---@param query_name string Name of the query (e.g., "highlights")
---@param text string Query text (unparsed).
function M.set(lang, query_name, text)
--- @diagnostic disable-next-line: undefined-field LuaLS bad at generics
M.get:clear(lang, query_name)
explicit_queries[lang][query_name] = M.parse(lang, text)
end
@@ -291,6 +292,7 @@ api.nvim_create_autocmd('OptionSet', {
pattern = { 'runtimepath' },
group = api.nvim_create_augroup('nvim.treesitter.query_cache_reset', { clear = true }),
callback = function()
--- @diagnostic disable-next-line: undefined-field LuaLS bad at generics
M.get:clear()
end,
})