Skip to content

Commit 9e51b77

Browse files
chore: add annotations to resolve unknown types
1 parent 5c0e241 commit 9e51b77

File tree

17 files changed

+46
-37
lines changed

17 files changed

+46
-37
lines changed

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 July 23
1+
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 July 28
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/core/command.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ function M.init()
2121
vim.api.nvim_create_user_command(M.name, M.command, {
2222
nargs = '*',
2323
desc = M.plugin .. ' commands',
24+
---@param cmdline string
25+
---@param col integer
26+
---@return string[]
2427
complete = function(_, cmdline, col)
2528
local line = cmdline:sub(1, col):match('^' .. M.name .. '%s+(.*)$')
2629
if line then
@@ -44,7 +47,7 @@ end
4447
---@param values string[]
4548
---@return string[]
4649
function M.matches(prefix, values)
47-
local result = {}
50+
local result = {} ---@type string[]
4851
for _, value in ipairs(values) do
4952
if vim.startswith(value, prefix) then
5053
result[#result + 1] = value
@@ -70,7 +73,7 @@ function M.run(fargs)
7073
return ('invalid # arguments - %d'):format(#fargs)
7174
end
7275
local name = fargs[1] or 'enable'
73-
local command = api[name]
76+
local command = api[name] --[[@as fun(enable?: boolean)?]]
7477
if not command then
7578
return ('invalid command - %s'):format(name)
7679
end

lua/render-markdown/core/log.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function M.add(level, name, ...)
125125
if M.level(level) < M.level(M.config.level) then
126126
return
127127
end
128-
local messages = {}
128+
local messages = {} ---@type string[]
129129
for i = 1, select('#', ...) do
130130
local value = select(i, ...)
131131
local message = type(value) == 'string' and value or vim.inspect(value)

lua/render-markdown/core/ts.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ function M.inject(language)
6262
else
6363
local files = vim.treesitter.query.get_files(language, 'injections')
6464
for _, file in ipairs(files) do
65-
local f = io.open(file, 'r')
66-
if f then
67-
query = query .. f:read('*all') .. '\n'
68-
f:close()
69-
end
65+
local f = assert(io.open(file, 'r'))
66+
local body = f:read('*a') --[[@as string]]
67+
f:close()
68+
query = query .. body .. '\n'
7069
end
7170
end
7271
query = query .. injection.query

lua/render-markdown/debug/diff.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ local M = {}
77
---@param t2 table<render.md.debug.Key, any>
88
---@return table<render.md.debug.Key, any>?
99
function M.get(t1, t2)
10-
local keys = vim.tbl_keys(t1)
10+
local keys = vim.tbl_keys(t1) ---@type render.md.debug.Key[]
1111
for key in pairs(t2) do
1212
if not vim.tbl_contains(keys, key) then
1313
keys[#keys + 1] = key
1414
end
1515
end
16-
local result = {}
16+
local result = {} ---@type table<render.md.debug.Key, any>
1717
for _, key in ipairs(keys) do
18-
local difference
18+
local difference ---@type any
1919
local v1, v2 = t1[key], t2[key]
2020
if type(v1) == 'table' and type(v2) == 'table' then
2121
difference = M.get(v1, v2)

lua/render-markdown/debug/marks.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ end
5555

5656
---@return string
5757
function Mark:__tostring()
58-
local lines = {}
58+
local lines = {} ---@type string[]
5959
lines[#lines + 1] = ('='):rep(vim.o.columns - 1)
6060
lines[#lines + 1] = ('row: %s'):format(Mark.collapse(self.row))
6161
lines[#lines + 1] = ('column: %s'):format(Mark.collapse(self.col))
@@ -64,7 +64,7 @@ function Mark:__tostring()
6464
---@param name string
6565
---@param f fun(value: any): string
6666
local function add(name, f)
67-
local value = self.opts[name]
67+
local value = self.opts[name] ---@type any
6868
if value ~= nil then
6969
lines[#lines + 1] = (' %s: %s'):format(name, f(value))
7070
end
@@ -106,7 +106,7 @@ end
106106
---@param line render.md.mark.Line
107107
---@return string
108108
function Mark.line(line)
109-
local result = {}
109+
local result = {} ---@type string[]
110110
for _, text in ipairs(line) do
111111
result[#result + 1] = ('(%s, %s)'):format(
112112
Mark.text(text[1]),
@@ -120,7 +120,7 @@ end
120120
---@param text string
121121
---@return string
122122
function Mark.text(text)
123-
local chars = vim.fn.str2list(text)
123+
local chars = vim.fn.str2list(text) ---@type integer[]
124124
local first, same = chars[1], true
125125
for _, char in ipairs(chars) do
126126
same = same and (first == char)

lua/render-markdown/debug/validator.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function Spec:list(keys, t, ts)
9393
if vim.tbl_contains(types, type(value)) then
9494
return true
9595
elseif type(value) == 'table' then
96+
---@cast value any[]
9697
for i, item in ipairs(value) do
9798
if type(item) ~= t then
9899
return false, ('[%d] is %s'):format(i, type(item))
@@ -114,8 +115,10 @@ function Spec:nested_list(keys, t, ts)
114115
if type(value) == t or vim.tbl_contains(types, type(value)) then
115116
return true
116117
elseif type(value) == 'table' then
118+
---@cast value any[]
117119
for i, item in ipairs(value) do
118120
if type(item) == 'table' then
121+
---@cast item any[]
119122
for j, nested in ipairs(item) do
120123
if type(nested) ~= t then
121124
local info = ('[%d][%d] is %s'):format(
@@ -150,6 +153,7 @@ function Spec:one_or_list_of(keys, values, ts)
150153
elseif type(value) ~= 'table' then
151154
return vim.tbl_contains(values, value)
152155
else
156+
---@cast value any[]
153157
for i, item in ipairs(value) do
154158
if not vim.tbl_contains(values, item) then
155159
return false, ('[%d] is %s'):format(i, item)
@@ -165,7 +169,7 @@ end
165169
---@param ts? type|type[]
166170
---@return type[], string
167171
function Spec:handle_types(custom, ts)
168-
local types
172+
local types ---@type type[]
169173
if not ts then
170174
types = {}
171175
elseif type(ts) == 'string' then
@@ -186,7 +190,7 @@ end
186190
---@param validation fun(v: any): boolean, string?
187191
function Spec:add(keys, kind, message, validation)
188192
if self.config then
189-
keys = type(keys) == 'table' and keys or { keys }
193+
keys = type(keys) == 'table' and keys or { keys } ---@type string[]
190194
for _, key in ipairs(keys) do
191195
self.specs[key] = {
192196
kind = kind,
@@ -223,12 +227,12 @@ Validator.spec = Spec.new
223227
---@param specs table<string, render.md.debug.Spec>
224228
function Validator:check(path, config, specs)
225229
for key, spec in pairs(specs) do
226-
local root = vim.list_extend({}, path)
230+
local root = vim.list_extend({}, path) ---@type string[]
227231
root[#root + 1] = tostring(key)
228232
local value = config[key]
229233
local ok, info = spec.validation(value)
230234
if not ok then
231-
local actual
235+
local actual ---@type string
232236
if spec.kind == Kind.data then
233237
actual = vim.inspect(value)
234238
elseif spec.kind == Kind.type then
@@ -245,7 +249,7 @@ function Validator:check(path, config, specs)
245249
end
246250
end
247251
for key in pairs(config) do
248-
local root = vim.list_extend({}, path)
252+
local root = vim.list_extend({}, path) ---@type string[]
249253
root[#root + 1] = tostring(key)
250254
if not specs[key] then
251255
local message = ('%s - invalid key'):format(table.concat(root, '.'))

lua/render-markdown/handler/latex.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function Handler:run(root)
4141

4242
local indent = self:indent(node.start_row, node.start_col)
4343
local lines = iter.list.map(self:expressions(node), function(expression)
44-
local line = vim.list_extend({}, indent)
44+
local line = vim.list_extend({}, indent) ---@type render.md.mark.Line
4545
line[#line + 1] = { expression, self.config.highlight }
4646
return line
4747
end)

lua/render-markdown/health.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.6.8'
8+
M.version = '8.6.9'
99

1010
function M.check()
1111
M.start('version')
@@ -153,7 +153,7 @@ end
153153
---@param name string
154154
---@param validate? fun(plugin: any): string[]?
155155
function M.plugin(name, validate)
156-
local has_plugin, plugin = pcall(require, name)
156+
local has_plugin, plugin = pcall(require, name) ---@type boolean, any
157157
if not has_plugin then
158158
vim.health.ok(name .. ': not installed')
159159
elseif not validate then

lua/render-markdown/lib/compat.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function M.fix_lsp_window(buf, win, extmarks)
2121
local str = require('render-markdown.lib.str')
2222

2323
-- account for conceal lines marks allowing us to reduce window height
24-
local height = vim.api.nvim_win_text_height(win, {}).all
24+
local height = vim.api.nvim_win_text_height(win, {}).all ---@type integer
2525
for _, extmark in ipairs(extmarks) do
2626
if extmark:get().opts.conceal_lines then
2727
height = height - 1

0 commit comments

Comments
 (0)