Skip to content

Commit

Permalink
feat: automatically typed module.required dependencies (#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrajano authored Jul 25, 2024
1 parent 28a247b commit 1985f2d
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 5 deletions.
43 changes: 42 additions & 1 deletion lua/neorg/core/modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,47 @@ local utils = require("neorg.core.utils")

--- @alias neorg.module.public { version: string, [any]: any }

--- @class (exact) neorg.module.resolver
--- @field ["core.autocommands"] core.autocommands
--- @field ["core.clipboard"] core.clipboard
--- @field ["core.completion"] core.completion
--- @field ["core.concealer"] core.concealer
--- @field ["core.dirman"] core.dirman
--- @field ["core.esupports.hop"] core.esupports.hop
--- @field ["core.esupports.indent"] core.esupports.indent
--- @field ["core.esupports.metagen"] core.esupports.metagen
--- @field ["core.export"] core.export
--- @field ["core.export.markdown"] core.export.markdown
--- @field ["core.fs"] core.fs
--- @field ["core.highlights"] core.highlights
--- @field ["core.integrations.treesitter"] core.integrations.treesitter
--- @field ["core.itero"] core.itero
--- @field ["core.journal"] core.journal
--- @field ["core.keybinds"] core.keybinds
--- @field ["core.latex.renderer"] core.latex.renderer
--- @field ["core.links"] core.links
--- @field ["core.looking-glass"] core.looking-glass
--- @field ["core.neorgcmd"] core.neorgcmd
--- @field ["core.pivot"] core.pivot
--- @field ["core.presenter"] core.presenter
--- @field ["core.promo"] core.promo
--- @field ["core.qol.toc"] core.qol.toc
--- @field ["core.qol.todo_items"] core.qol.todo_items
--- @field ["core.queries.native"] core.queries.native
--- @field ["core.scanner"] core.scanner
--- @field ["core.storage"] core.storage
--- @field ["core.summary"] core.summary
--- @field ["core.syntax"] core.syntax
--- @field ["core.tangle"] core.tangle
--- @field ["core.tempus"] core.tempus
--- @field ["core.text-objects"] core.text-objects
--- @field ["core.todo-introspector"] core.todo-introspector
--- @field ["core.ui"] core.ui
--- @field ["core.ui.calendar"] core.ui.calendar
--- @field ["core.ui.calendar.views.monthly"] core.ui.calendar.views.monthly
--- @field ["core.ui.selection_popup"] core.ui.selection_popup
--- @field ["core.ui.text_popup"] core.ui.text_popup

--- Defines both a public and private configuration for a Neorg module.
--- Public configurations may be tweaked by the user from the `neorg.setup()` function,
--- whereas private configurations are for internal use only.
Expand Down Expand Up @@ -41,7 +82,7 @@ local utils = require("neorg.core.utils")
--- @field path string The full path to the module (a more verbose version of `name`). May be used in lua's `require()` statements.
--- @field public private? table A convenience table to place all of your private variables that you don't want to expose.
--- @field public public? neorg.module.public Every module can expose any set of information it sees fit through this field. All functions and variables declared in this table will be visiable to any other module loaded.
--- @field required? table<string, neorg.module.public> Contains the public tables of all modules that were required via the `requires` array provided in the `setup()` function of this module.
--- @field required? neorg.module.resolver Contains the public tables of all modules that were required via the `requires` array provided in the `setup()` function of this module.
--- @field setup? fun(): neorg.module.setup? Function that is invoked before any other loading occurs. Should perform preliminary startup tasks.
--- @field replaced? boolean If `true`, this means the module is a replacement for a core module. This flag is set automatically whenever `setup().replaces` is set to a value.
--- @field on_event fun(event: neorg.event) A callback that is invoked any time an event the module has subscribed to has fired.
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/clipboard/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.private = {
callbacks = {},
}

--- @class core.clipboard
module.public = {
add_callback = function(node_type, func, strict)
module.private.callbacks[node_type] = module.private.callbacks[node_type] or {}
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/export/markdown/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ module.config.public = {
extension = "md",
}

--- @class core.export.markdown
module.public = {
export = {
init_state = function()
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/export/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ module.config.public = {
export_dir = "<export-dir>/<language>-export",
}

---@class core.export
module.public = {
--- Returns a module that can handle conversion from `.norg` to the target filetype
---@param ftype string #The filetype to export to
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/fs/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local modules = neorg.modules

local module = modules.create("core.fs")

---@class core.fs
module.public = {
directory_map = function(path, callback)
for name, type in vim.fs.dir(path) do
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/itero/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module.load = function()
vim.keymap.set("!", "<Plug>(neorg.itero.next-iteration)", module.public.next_iteration_cr)
end

---@class core.itero
module.public = {
next_iteration_cr = function()
local cursor = vim.api.nvim_win_get_cursor(0)
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/journal/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ module.config.private = {
},
}

---@class core.journal
module.public = {
version = "0.0.9",
}
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/keybinds/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.config.public = {
preset = "neorg",
}

---@class core.keybinds
module.public = {
--- Adds a set of default keys for Neorg to bind.
--- Should be used exclusively by external modules wanting to provide their own default keymaps.
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/latex/renderer/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ module.private.get_key = function(range)
return ("%d:%d"):format(range[1], range[2])
end

---@class core.latex.renderer
module.public = {
---@async
---@param buf number
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/looking-glass/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.load = function()
vim.keymap.set("", "<Plug>(neorg.looking-glass.magnify-code-block)", module.public.magnify_code_block)
end

---@class core.looking-glass
module.public = {
sync_text_segment = function(source, source_window, source_start, source_end, target, target_window)
-- Create a unique but deterministic namespace name for the code block
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/pivot/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module.private = {
end,
}

---@class core.pivot
module.public = {
---@param invert boolean
change_list = neorg.utils.wrap_dotrepeat(function(invert)
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/qol/todo_items/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ module.config.public = {
---|"urgent"
---|"uncertain"

---@class core.qol.todo_items
module.private = {
--- Updates the parent todo item for the current todo item if it exists
---@param recursion_level number the index of the parent to change. The higher the number the more the code will traverse up the syntax tree.
Expand Down Expand Up @@ -420,6 +419,7 @@ local function task_set(character, name)
end)
end

---@class core.qol.todo_items
module.public = {
["task-done"] = task_set("x", "done"),
["task-undone"] = task_set(" ", "undone"),
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/summary/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ module.config.public = {
strategy = "default",
}

---@class core.summary
module.public = {
---@param buf integer? the buffer to insert the summary to
---@param cursor_pos integer[]? a tuple of row, col of the cursor positon (see nvim_win_get_cursor())
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/syntax/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.private = {
available_languages = {},
}

---@class core.syntax
module.public = {

-- fills module.private.loaded_code_blocks with the list of active code blocks in the buffer
Expand Down
1 change: 1 addition & 0 deletions lua/neorg/modules/core/tangle/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ local function get_comment_string(language)
return commentstring
end

---@class core.tangle
module.public = {
tangle = function(buffer)
---@type core.integrations.treesitter
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/text-objects/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ module.config.public = {
},
}

---@class core.text-objects
module.private = {
get_element_from_cursor = function(node_pattern)
local node_at_cursor = vim.treesitter.get_node()
Expand Down Expand Up @@ -165,6 +164,7 @@ module.private = {
end,
}

---@class core.text-objects
module.public = {
move_up = function()
local config = module.config.public.moveables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ module.private = {
end,
}

---@class core.ui.calendar.views.monthly
module.public = {

view_name = "monthly",
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/ui/selection_popup/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local lib = neorg.lib

local module = modules.create("core.ui.selection_popup")

---@class core.ui
---@class core.ui.selection_popup
module.public = {
--- Constructs a new selection
---@param buffer number #The number of the buffer the selection should attach to
Expand Down
2 changes: 1 addition & 1 deletion lua/neorg/modules/core/ui/text_popup/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local modules = neorg.modules

local module = modules.create("core.ui.text_popup")

---@class core.ui
---@class core.ui.text_popup
module.public = {
--- Opens a floating window at the specified position and asks for user input
---@param name string #The name of the floating window
Expand Down

0 comments on commit 1985f2d

Please sign in to comment.