Skip to content

Commit

Permalink
fix: improve startup time by removing pcall on every module load
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Jul 14, 2024
1 parent 5cc4111 commit 7d9bd33
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 25 deletions.
17 changes: 1 addition & 16 deletions lua/neorg/core/modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,22 +439,7 @@ function modules.load_module(module_name, cfg)
end

-- Attempt to require the module, does not throw an error if the module doesn't exist
local exists, module = pcall(require, "neorg.modules." .. module_name .. ".module")

-- If the module doesn't exist then return false
if not exists then
local fallback_exists, fallback_module = pcall(require, "neorg.modules." .. module_name)

if not fallback_exists then
log.error(
"Unable to load module '" .. module_name .. "'. The module probably does not exist! Stacktrace: ",
module
)
return false
end

module = fallback_module
end
local module = require("neorg.modules." .. module_name .. ".module")

-- If the module is nil for some reason return false
if not module then
Expand Down
9 changes: 0 additions & 9 deletions lua/neorg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ function neorg.org_file_entered(manual, arguments)

-- Go through each defined module and grab its config
for name, module in pairs(module_list) do
-- If the module's data is not empty and we have not defined a config table then it probably means there's junk in there
if not vim.tbl_isempty(module) and not module.config then
log.warn(
"Potential bug detected in",
name,
"- nonstandard tables found in the module definition. Did you perhaps mean to put these tables inside of the config = {} table?"
)
end

-- Apply the config
config.modules[name] = vim.tbl_deep_extend("force", config.modules[name] or {}, module.config or {})
end
Expand Down
File renamed without changes.

0 comments on commit 7d9bd33

Please sign in to comment.