Skip to content

Commit c3afe21

Browse files
committed
chore: fix a bunch of type errors
1 parent 45f51ed commit c3afe21

File tree

11 files changed

+47
-43
lines changed

11 files changed

+47
-43
lines changed

docgen/docgen.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
local neorg = require("neorg.core")
2-
local lib, modules, utils = neorg.lib, neorg.modules, neorg.utils
2+
local lib, modules, utils, log = neorg.lib, neorg.modules, neorg.utils, neorg.log
33

44
local docgen = {}
55

@@ -174,7 +174,7 @@ end
174174
--- Recursively maps over each item in the `module.config.public` table,
175175
-- invoking a callback on each run. Also descends down recursive tables.
176176
---@param buffer number #Buffer ID
177-
---@param start_node userdata #The node to start parsing
177+
---@param start_node table #The node to start parsing
178178
---@param callback fun(ConfigOptionData, table) #Invoked on each node with the corresponding data
179179
---@param parents string[]? #Used internally to track nesting levels
180180
docgen.map_config = function(buffer, start_node, callback, parents)
@@ -184,7 +184,7 @@ docgen.map_config = function(buffer, start_node, callback, parents)
184184
local comments = {}
185185
local index = 1
186186

187-
for node in start_node:iter_children() do ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
187+
for node in start_node:iter_children() do
188188
if node:type() == "comment" then
189189
table.insert(comments, ts.get_node_text(node, buffer))
190190
elseif node:type() == "field" then
@@ -675,7 +675,7 @@ docgen.htmlify = function(configuration_option)
675675
local text = ts.get_node_text(self.data.value, self.buffer):match("^function%s*(%b())")
676676

677677
if not text then
678-
log.error(string.format("Unable to parse function, perhaps some wrong formatting?")) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
678+
log.error(string.format("Unable to parse function, perhaps some wrong formatting?"))
679679
table.insert(result, "<error: incorrect formatting>")
680680
return
681681
end

lua/neorg/core/log.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ log.new = function(config, standalone)
137137

138138
-- Output to log file
139139
if config.use_file then
140-
local fp = io.open(outfile, "a")
140+
local fp = assert(io.open(outfile, "a"))
141141
local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg)
142-
fp:write(str) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
143-
fp:close() ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
142+
fp:write(str)
143+
fp:close()
144144
end
145145
end
146146

lua/neorg/modules/core/clipboard/module.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.load = function()
3737

3838
while node:parent() do
3939
if module.private.callbacks[node:type()] then
40-
local register = vim.fn.getreg(vim.v.register)
40+
local register = vim.fn.getreg(assert(vim.v.register))
4141

4242
vim.fn.setreg(
4343
vim.v.register,
@@ -49,9 +49,9 @@ module.load = function()
4949
return callback.cb(
5050
node,
5151
vim.split(
52-
register,
52+
assert(register --[[@as string]]),
5353
"\n",
54-
{ ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
54+
{
5555
plain = true,
5656
-- TODO: This causes problems in places
5757
-- where you actually want to copy
@@ -66,7 +66,7 @@ module.load = function()
6666
}
6767
)
6868
end) or register,
69-
"l" ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
69+
"l" ---@diagnostic disable-line
7070
)
7171

7272
return

lua/neorg/modules/core/concealer/module.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ local function remove_extmarks(bufid, pos_start_0b_0b, pos_end_0bin_0bex)
996996
end
997997
end
998998

999-
local function is_inside_example(_node) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
999+
local function is_inside_example(_)
10001000
-- TODO: waiting for parser fix
10011001
return false
10021002
end

lua/neorg/modules/core/esupports/hop/module.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ end
6161
---@class core.esupports.hop
6262
module.public = {
6363
--- Follow link from a specific node
64-
---@param node userdata
64+
---@param node table
6565
---@param open_mode string|nil if not nil, will open a new split with the split mode defined (vsplitr...) or new tab (mode="tab") or with external app (mode="external")
6666
---@param parsed_link table a table of link information gathered from parse_link()
6767
follow_link = function(node, open_mode, parsed_link)
68-
if node:type() == "anchor_declaration" then ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
68+
if node:type() == "anchor_declaration" then
6969
local located_anchor_declaration = module.public.locate_anchor_declaration_target(node)
7070

7171
if not located_anchor_declaration then
@@ -335,9 +335,9 @@ module.public = {
335335
end,
336336

337337
--- Locates the node that an anchor is pointing to
338-
---@param anchor_decl_node userdata #A valid anchod declaration node
338+
---@param anchor_decl_node table #A valid anchod declaration node
339339
locate_anchor_declaration_target = function(anchor_decl_node)
340-
if not anchor_decl_node:named_child(0) then ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
340+
if not anchor_decl_node:named_child(0) then
341341
return
342342
end
343343

lua/neorg/modules/core/export/module.lua

+15-12
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ module.public = {
118118
local ts_utils = module.required["core.integrations.treesitter"].get_ts_utils()
119119

120120
--- Descends down a node and its children
121-
---@param start userdata #The TS node to begin at
121+
---@param start table #The TS node to begin at
122122
---@return string #The exported/converted node as a string
123123
local function descend(start)
124124
-- We do not want to parse erroneous nodes, so we skip them instead
125-
if start:type() == "ERROR" then ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
125+
if start:type() == "ERROR" then
126126
return ""
127127
end
128128

129129
local output = {}
130130

131-
for node in start:iter_children() do ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
131+
for node in start:iter_children() do
132132
-- See if there is a conversion function for the specific node type we're dealing with
133133
local exporter = converter.export.functions[node:type()]
134134

@@ -201,7 +201,7 @@ module.public = {
201201
--
202202
-- The recollector can encounter a `definition` node, see the nodes it is made up of ({ ": ", "Term", "Definition" })
203203
-- and rearrange its components to { "Term", ": ", "Definition" } to then achieve the desired result.
204-
local recollector = converter.export.recollectors[start:type()] ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
204+
local recollector = converter.export.recollectors[start:type()]
205205

206206
return recollector and table.concat(recollector(output, state, start, ts_utils) or {})
207207
or (not vim.tbl_isempty(output) and table.concat(output))
@@ -220,19 +220,20 @@ module.on_event = function(event)
220220
-- Example: Neorg export to-file my-custom-file markdown
221221

222222
local filepath = vim.fn.expand(event.content[1])
223-
local filetype = event.content[2] or vim.filetype.match({ filename = filepath }) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
224-
local exported = module.public.export(event.buffer, filetype) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
223+
local filetype = event.content[2] or vim.filetype.match({ filename = filepath })
224+
local exported = module.public.export(event.buffer, filetype)
225225

226226
vim.loop.fs_open(
227-
filepath, ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
227+
filepath,
228228
"w",
229229
438,
230230
function(err, fd)
231231
assert(not err, lib.lazy_string_concat("Failed to open file '", filepath, "' for export: ", err))
232+
assert(fd)
232233

233234
vim.loop.fs_write(
234-
fd, ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
235-
exported, ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
235+
fd,
236+
exported,
236237
0,
237238
function(werr)
238239
assert(
@@ -259,11 +260,12 @@ module.on_event = function(event)
259260

260261
vim.loop.fs_scandir(event.content[1], function(err, handle)
261262
assert(not err, lib.lazy_string_concat("Failed to scan directory '", event.content[1], "': ", err))
263+
assert(handle)
262264

263265
local file_counter, parsed_counter = 0, 0
264266

265267
while true do
266-
local name, type = vim.loop.fs_scandir_next(handle) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
268+
local name, type = vim.loop.fs_scandir_next(handle)
267269

268270
if not name then
269271
break
@@ -287,7 +289,7 @@ module.on_event = function(event)
287289

288290
vim.opt.eventignore = "BufEnter"
289291

290-
local buffer = vim.fn.bufadd(filepath)
292+
local buffer = assert(vim.fn.bufadd(filepath))
291293
vim.fn.bufload(buffer)
292294

293295
vim.opt.eventignore = old_event_ignore
@@ -308,9 +310,10 @@ module.on_event = function(event)
308310
not fs_err,
309311
lib.lazy_string_concat("Failed to open file '", write_path, "' for export: ", fs_err)
310312
)
313+
assert(fd)
311314

312315
vim.loop.fs_write(
313-
fd, ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
316+
fd,
314317
exported,
315318
0,
316319
function(werr)

lua/neorg/modules/core/highlights/module.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ module.public = {
449449

450450
--- Recursively descends down the highlight configuration and applies every highlight accordingly
451451
---@param highlights table #The table of highlights to descend down
452-
---@param callback any #(function(hl_name, highlight, prefix) -> bool) - a callback function to be invoked for every highlight. If it returns true then we should recurse down the table tree further ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
452+
---@param callback fun(hl_name: string, highlight: table, prefix: string): boolean? #A callback function to be invoked for every highlight. If it returns true then we should recurse down the table tree further ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
453453
---@param prefix string #Should be only used by the function itself, acts as a "savestate" so the function can keep track of what path it has descended down
454454
local function descend(highlights, callback, prefix)
455455
-- Loop through every highlight defined in the provided table

lua/neorg/modules/core/keybinds/module.lua

+7-6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.load = function()
7474
module.required["core.autocommands"].enable_autocommand("BufLeave")
7575

7676
if module.config.public.hook then
77-
neorg.callbacks.on_event( ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
77+
neorg.callbacks.on_event(
7878
"core.keybinds.events.enable_keybinds",
7979
function(_, keybinds)
8080
module.config.public.hook(keybinds)
@@ -147,7 +147,7 @@ module.public = {
147147

148148
--- Like register_keybind(), except registers a batch of them
149149
---@param module_name string #The name of the module that owns the keybind. Make sure it's an absolute path.
150-
---@param names any #list of strings - a list of strings detailing names of the keybinds. The module_name will be prepended to each one to form a unique name. ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
150+
---@param names string[] #A list of strings detailing names of the keybinds. The module_name will be prepended to each one to form a unique name.
151151
register_keybinds = function(module_name, names)
152152
-- Loop through each name from the names argument
153153
for _, name in ipairs(names) do
@@ -296,8 +296,9 @@ module.public = {
296296

297297
--- An advanced wrapper around the map() function, maps several keys if the current neorg mode is the desired one
298298
---@param mode string #The neorg mode to bind the keys on
299-
---@param keys any #table { <neovim_mode> = { { "<key>", "<name-of-keybind>", custom_opts } } } - a table of keybinds ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
300-
---@param opts any #table) - the same parameters that should be passed into vim.keymap.set('s opts parameter ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
299+
---@param keys { [string]: { [1]: string, [2]: string, [3]: table }[] } #A table of keybinds
300+
---@param opts table #The same parameters that should be passed into vim.keymap.set()'s opts parameter
301+
---@see vim.keymap.set
301302
map_to_mode = function(mode, keys, opts)
302303
-- If the keys table is empty then don't bother doing any parsing
303304
if vim.tbl_isempty(keys) then
@@ -319,8 +320,8 @@ module.public = {
319320

320321
--- An advanced wrapper around the map() function, maps several keys if the current neorg mode is the desired one
321322
---@param mode string #The neorg mode to bind the keys on
322-
---@param keys any #table { <neovim_mode> = { { "<key>", "<name-of-keybind>", custom_opts } } } - a table of keybinds ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
323-
---@param opts any #table) - the same parameters that should be passed into vim.keymap.set('s opts parameter ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
323+
---@param keys { [string]: { [1]: string, [2]: string, [3]: table, opts?: table }[] } #A table of keybinds
324+
---@param opts table #The same parameters that should be passed into vim.keymap.set()'s opts parameter
324325
map_event_to_mode = function(mode, keys, opts)
325326
-- If the keys table is empty then don't bother doing any parsing
326327
if vim.tbl_isempty(keys) then

lua/neorg/modules/core/neorgcmd/module.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.examples = {
2424
-- In your module.setup(), make sure to require core.neorgcmd (requires = { "core.neorgcmd" })
2525
-- Afterwards in a function of your choice that gets called *after* core.neorgcmd gets intialized e.g. load():
2626

27-
module.load = function() ---@diagnostic disable-line -- TODO: type error workaround <pysan3> Duplicate field `load` (L94)
27+
module.load = function()
2828
module.required["core.neorgcmd"].add_commands_from_table({
2929
-- The name of our command
3030
my_command = {
@@ -193,8 +193,8 @@ module.public = {
193193
end
194194
end,
195195

196-
--- Defines a custom completion function to use for core.neorgcmd.
197-
---@param callback any #(function) - the same function format as you would receive by being called by :command -completion=customlist,v:lua.callback Neorg ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
196+
--- Defines a custom completion function to use for `core.neorgcmd`.
197+
---@param callback function The same function format as you would receive by being called by `:command -completion=customlist,v:lua.callback Neorg`.
198198
set_completion_callback = function(callback)
199199
module.private.generate_completions = callback
200200
end,
@@ -206,7 +206,7 @@ module.private = {
206206
local args = data.fargs
207207

208208
local current_buf = vim.api.nvim_get_current_buf()
209-
local is_norg = vim.api.nvim_buf_get_option(current_buf, "filetype") == "norg"
209+
local is_norg = vim.bo[current_buf].filetype == "norg"
210210

211211
local function check_condition(condition)
212212
if condition == nil then

lua/neorg/modules/core/ui/module.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module.public = {
101101

102102
local bufname = "neorg://" .. name
103103

104-
if vim.fn.bufexists(bufname) == 1 then ---@diagnostic disable-line -- TODO: type error workaround <pysan3>: cannot assign `string` to parameter `integer`
104+
if vim.fn.bufexists(bufname) == 1 then
105105
log.error("Buffer '" .. name .. "' already exists")
106106
return
107107
end
@@ -243,7 +243,7 @@ module.public = {
243243
return vim.tbl_isempty(elem) or (elem[3] == nil and true or elem[3])
244244
end, content))
245245

246-
vim.api.nvim_buf_set_lines(buf, 0, length, false, vim.split(("\n"):rep(length), "\n", true)) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
246+
vim.api.nvim_buf_set_lines(buf, 0, length, false, vim.split(("\n"):rep(length), "\n", { plain = true }))
247247

248248
local line_number = 1
249249
local buffer = {}
@@ -370,7 +370,7 @@ module.examples = {
370370
-- Binds a selection to that buffer
371371
local selection = module
372372
.public
373-
.begin_selection(buffer) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
373+
.begin_selection(buffer)
374374
:apply({
375375
-- A title will simply be text with a custom highlight
376376
title = function(self, text)

lua/neorg/modules/core/ui/selection_popup.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ module.public = {
272272
else
273273
return callback and callback.callback or function() end
274274
end
275-
end)()(data) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
275+
end)()()
276276
end)
277277

278278
-- Actually render the flag

0 commit comments

Comments
 (0)