Skip to content

Commit

Permalink
perf: lazy-load integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 22, 2024
1 parent 02f1055 commit f5d344d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lua/lazydev/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ function M.setup(opts)

vim.schedule(function()
require("lazydev.buf").setup()
for name, enabled in pairs(options.integrations) do
if enabled then
require("lazydev.integrations." .. name).setup()
end
end
require("lazydev.integrations").setup()
end)
return options
end
Expand Down
53 changes: 53 additions & 0 deletions lua/lazydev/integrations/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
local Config = require("lazydev.config")

local M = {}

M.plugins = {
["nvim-cmp"] = "cmp",
["coq_nvim"] = "coq",
lspconfig = "lspconfig",
}

---@type table<string, boolean>
M.loaded = {}

function M.setup()
if package.loaded.lazy then
local LazyConfig = require("lazy.core.config")
vim.api.nvim_create_autocmd("User", {
group = vim.api.nvim_create_augroup("lazydev-integrations", { clear = true }),
pattern = "LazyLoad",
callback = function(event)
local name = M.plugins[event.data]
if name then
M.load(name)
end
end,
})
for name, enabled in pairs(Config.integrations) do
if enabled then
local plugin = LazyConfig.plugins[M.plugins[name]]
local is_loaded = plugin and plugin._.loaded
if is_loaded then
M.load(name)
end
end
end
else
for name, enabled in pairs(Config.integrations) do
if enabled then
M.load(name)
end
end
end
end

---@param name string
function M.load(name)
if not M.loaded[name] then
M.loaded[name] = true
require("lazydev.integrations." .. name).setup()
end
end

return M

0 comments on commit f5d344d

Please sign in to comment.