diff --git a/docgen/docgen.lua b/docgen/docgen.lua index c8f91669b..8e4143eaa 100644 --- a/docgen/docgen.lua +++ b/docgen/docgen.lua @@ -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 = {} @@ -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) @@ -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 + 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 @@ -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 + log.error(string.format("Unable to parse function, perhaps some wrong formatting?")) table.insert(result, "") return end diff --git a/lua/neorg/core/log.lua b/lua/neorg/core/log.lua index 9e2aced7e..42537edce 100644 --- a/lua/neorg/core/log.lua +++ b/lua/neorg/core/log.lua @@ -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 - fp:close() ---@diagnostic disable-line -- TODO: type error workaround + fp:write(str) + fp:close() end end diff --git a/lua/neorg/modules/core/clipboard/module.lua b/lua/neorg/modules/core/clipboard/module.lua index 1cdd957e9..5b32893cb 100644 --- a/lua/neorg/modules/core/clipboard/module.lua +++ b/lua/neorg/modules/core/clipboard/module.lua @@ -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, @@ -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 + { plain = true, -- TODO: This causes problems in places -- where you actually want to copy @@ -66,7 +66,7 @@ module.load = function() } ) end) or register, - "l" ---@diagnostic disable-line -- TODO: type error workaround + "l" ---@diagnostic disable-line ) return diff --git a/lua/neorg/modules/core/concealer/module.lua b/lua/neorg/modules/core/concealer/module.lua index a9351a1ae..5e155ff93 100644 --- a/lua/neorg/modules/core/concealer/module.lua +++ b/lua/neorg/modules/core/concealer/module.lua @@ -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 +local function is_inside_example(_) -- TODO: waiting for parser fix return false end diff --git a/lua/neorg/modules/core/esupports/hop/module.lua b/lua/neorg/modules/core/esupports/hop/module.lua index 30e52fcd6..e58e97793 100644 --- a/lua/neorg/modules/core/esupports/hop/module.lua +++ b/lua/neorg/modules/core/esupports/hop/module.lua @@ -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 + if node:type() == "anchor_declaration" then local located_anchor_declaration = module.public.locate_anchor_declaration_target(node) if not located_anchor_declaration then @@ -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 + if not anchor_decl_node:named_child(0) then return end diff --git a/lua/neorg/modules/core/export/module.lua b/lua/neorg/modules/core/export/module.lua index ee9457a71..245307845 100644 --- a/lua/neorg/modules/core/export/module.lua +++ b/lua/neorg/modules/core/export/module.lua @@ -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 + if start:type() == "ERROR" then return "" end local output = {} - for node in start:iter_children() do ---@diagnostic disable-line -- TODO: type error workaround + 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()] @@ -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 + 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)) @@ -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 - local exported = module.public.export(event.buffer, filetype) ---@diagnostic disable-line -- TODO: type error workaround + 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 + 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 - exported, ---@diagnostic disable-line -- TODO: type error workaround + fd, + exported, 0, function(werr) assert( @@ -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 + local name, type = vim.loop.fs_scandir_next(handle) if not name then break @@ -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 @@ -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 + fd, exported, 0, function(werr) diff --git a/lua/neorg/modules/core/highlights/module.lua b/lua/neorg/modules/core/highlights/module.lua index ae751a9b4..622a572a6 100644 --- a/lua/neorg/modules/core/highlights/module.lua +++ b/lua/neorg/modules/core/highlights/module.lua @@ -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 + ---@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 ---@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 diff --git a/lua/neorg/modules/core/keybinds/module.lua b/lua/neorg/modules/core/keybinds/module.lua index bd9a0af92..b06da6c26 100644 --- a/lua/neorg/modules/core/keybinds/module.lua +++ b/lua/neorg/modules/core/keybinds/module.lua @@ -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 + neorg.callbacks.on_event( "core.keybinds.events.enable_keybinds", function(_, keybinds) module.config.public.hook(keybinds) @@ -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 + ---@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 @@ -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 { = { { "", "", custom_opts } } } - a table of keybinds ---@diagnostic disable-line -- TODO: type error workaround - ---@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 + ---@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 @@ -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 { = { { "", "", custom_opts } } } - a table of keybinds ---@diagnostic disable-line -- TODO: type error workaround - ---@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 + ---@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 diff --git a/lua/neorg/modules/core/neorgcmd/module.lua b/lua/neorg/modules/core/neorgcmd/module.lua index 4bd162874..b8852c930 100644 --- a/lua/neorg/modules/core/neorgcmd/module.lua +++ b/lua/neorg/modules/core/neorgcmd/module.lua @@ -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 Duplicate field `load` (L94) + module.load = function() module.required["core.neorgcmd"].add_commands_from_table({ -- The name of our command my_command = { @@ -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 + --- 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, @@ -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 diff --git a/lua/neorg/modules/core/ui/module.lua b/lua/neorg/modules/core/ui/module.lua index faee47f4e..9f4d6ef13 100644 --- a/lua/neorg/modules/core/ui/module.lua +++ b/lua/neorg/modules/core/ui/module.lua @@ -101,7 +101,7 @@ module.public = { local bufname = "neorg://" .. name - if vim.fn.bufexists(bufname) == 1 then ---@diagnostic disable-line -- TODO: type error workaround : cannot assign `string` to parameter `integer` + if vim.fn.bufexists(bufname) == 1 then log.error("Buffer '" .. name .. "' already exists") return end @@ -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 + vim.api.nvim_buf_set_lines(buf, 0, length, false, vim.split(("\n"):rep(length), "\n", { plain = true })) local line_number = 1 local buffer = {} @@ -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 + .begin_selection(buffer) :apply({ -- A title will simply be text with a custom highlight title = function(self, text) diff --git a/lua/neorg/modules/core/ui/selection_popup.lua b/lua/neorg/modules/core/ui/selection_popup.lua index 8a041dd63..c2ae33907 100644 --- a/lua/neorg/modules/core/ui/selection_popup.lua +++ b/lua/neorg/modules/core/ui/selection_popup.lua @@ -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 + end)()() end) -- Actually render the flag