Skip to content

Commit

Permalink
chore: fix a bunch of type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Feb 22, 2024
1 parent 45f51ed commit c3afe21
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 43 deletions.
8 changes: 4 additions & 4 deletions docgen/docgen.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local neorg = require("neorg.core")
local lib, modules, utils = neorg.lib, neorg.modules, neorg.utils
local lib, modules, utils, log = neorg.lib, neorg.modules, neorg.utils, neorg.log

local docgen = {}

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

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

if not text then
log.error(string.format("Unable to parse function, perhaps some wrong formatting?")) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
log.error(string.format("Unable to parse function, perhaps some wrong formatting?"))
table.insert(result, "<error: incorrect formatting>")
return
end
Expand Down
6 changes: 3 additions & 3 deletions lua/neorg/core/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ log.new = function(config, standalone)

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

Expand Down
8 changes: 4 additions & 4 deletions lua/neorg/modules/core/clipboard/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.load = function()

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

vim.fn.setreg(
vim.v.register,
Expand All @@ -49,9 +49,9 @@ module.load = function()
return callback.cb(
node,
vim.split(
register,
assert(register --[[@as string]]),
"\n",
{ ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
{
plain = true,
-- TODO: This causes problems in places
-- where you actually want to copy
Expand All @@ -66,7 +66,7 @@ module.load = function()
}
)
end) or register,
"l" ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
"l" ---@diagnostic disable-line
)

return
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/concealer/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ local function remove_extmarks(bufid, pos_start_0b_0b, pos_end_0bin_0bex)
end
end

local function is_inside_example(_node) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
local function is_inside_example(_)
-- TODO: waiting for parser fix
return false
end
Expand Down
8 changes: 4 additions & 4 deletions lua/neorg/modules/core/esupports/hop/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ end
---@class core.esupports.hop
module.public = {
--- Follow link from a specific node
---@param node userdata
---@param node table
---@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")
---@param parsed_link table a table of link information gathered from parse_link()
follow_link = function(node, open_mode, parsed_link)
if node:type() == "anchor_declaration" then ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
if node:type() == "anchor_declaration" then
local located_anchor_declaration = module.public.locate_anchor_declaration_target(node)

if not located_anchor_declaration then
Expand Down Expand Up @@ -335,9 +335,9 @@ module.public = {
end,

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

Expand Down
27 changes: 15 additions & 12 deletions lua/neorg/modules/core/export/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ module.public = {
local ts_utils = module.required["core.integrations.treesitter"].get_ts_utils()

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

local output = {}

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

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

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

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

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

vim.loop.fs_write(
fd, ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
exported, ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
fd,
exported,
0,
function(werr)
assert(
Expand All @@ -259,11 +260,12 @@ module.on_event = function(event)

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

local file_counter, parsed_counter = 0, 0

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

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

vim.opt.eventignore = "BufEnter"

local buffer = vim.fn.bufadd(filepath)
local buffer = assert(vim.fn.bufadd(filepath))
vim.fn.bufload(buffer)

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

vim.loop.fs_write(
fd, ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
fd,
exported,
0,
function(werr)
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/highlights/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ module.public = {

--- Recursively descends down the highlight configuration and applies every highlight accordingly
---@param highlights table #The table of highlights to descend down
---@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>
---@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>
---@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
local function descend(highlights, callback, prefix)
-- Loop through every highlight defined in the provided table
Expand Down
13 changes: 7 additions & 6 deletions lua/neorg/modules/core/keybinds/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.load = function()
module.required["core.autocommands"].enable_autocommand("BufLeave")

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

--- Like register_keybind(), except registers a batch of them
---@param module_name string #The name of the module that owns the keybind. Make sure it's an absolute path.
---@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>
---@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.
register_keybinds = function(module_name, names)
-- Loop through each name from the names argument
for _, name in ipairs(names) do
Expand Down Expand Up @@ -296,8 +296,9 @@ module.public = {

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

--- An advanced wrapper around the map() function, maps several keys if the current neorg mode is the desired one
---@param mode string #The neorg mode to bind the keys on
---@param keys any #table { <neovim_mode> = { { "<key>", "<name-of-keybind>", custom_opts } } } - a table of keybinds ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
---@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>
---@param keys { [string]: { [1]: string, [2]: string, [3]: table, opts?: table }[] } #A table of keybinds
---@param opts table #The same parameters that should be passed into vim.keymap.set()'s opts parameter
map_event_to_mode = function(mode, keys, opts)
-- If the keys table is empty then don't bother doing any parsing
if vim.tbl_isempty(keys) then
Expand Down
8 changes: 4 additions & 4 deletions lua/neorg/modules/core/neorgcmd/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.examples = {
-- In your module.setup(), make sure to require core.neorgcmd (requires = { "core.neorgcmd" })
-- Afterwards in a function of your choice that gets called *after* core.neorgcmd gets intialized e.g. load():

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

--- Defines a custom completion function to use for core.neorgcmd.
---@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>
--- Defines a custom completion function to use for `core.neorgcmd`.
---@param callback function The same function format as you would receive by being called by `:command -completion=customlist,v:lua.callback Neorg`.
set_completion_callback = function(callback)
module.private.generate_completions = callback
end,
Expand All @@ -206,7 +206,7 @@ module.private = {
local args = data.fargs

local current_buf = vim.api.nvim_get_current_buf()
local is_norg = vim.api.nvim_buf_get_option(current_buf, "filetype") == "norg"
local is_norg = vim.bo[current_buf].filetype == "norg"

local function check_condition(condition)
if condition == nil then
Expand Down
6 changes: 3 additions & 3 deletions lua/neorg/modules/core/ui/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.public = {

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

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

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>
vim.api.nvim_buf_set_lines(buf, 0, length, false, vim.split(("\n"):rep(length), "\n", { plain = true }))

local line_number = 1
local buffer = {}
Expand Down Expand Up @@ -370,7 +370,7 @@ module.examples = {
-- Binds a selection to that buffer
local selection = module
.public
.begin_selection(buffer) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
.begin_selection(buffer)
:apply({
-- A title will simply be text with a custom highlight
title = function(self, text)
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/ui/selection_popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ module.public = {
else
return callback and callback.callback or function() end
end
end)()(data) ---@diagnostic disable-line -- TODO: type error workaround <pysan3>
end)()()
end)

-- Actually render the flag
Expand Down

0 comments on commit c3afe21

Please sign in to comment.