Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
refact: Switch to lazy.nvim and improve lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
connorgmeean committed Jan 14, 2023
1 parent df6b2c6 commit 56c0c3b
Show file tree
Hide file tree
Showing 38 changed files with 76 additions and 161 deletions.
14 changes: 14 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ end
local profiler = require("doom.services.profiler")
profiler.start("framework|init.lua")

-- Preload lazy nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
print("Bootstrapping lazy.nvim, please wait...")
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)

-- Makes sure ~/.local/share/nvim exists, to prevent problems with logging
vim.fn.mkdir(vim.fn.stdpath("data"), "p")
Expand Down
5 changes: 0 additions & 5 deletions lua/doom/core/doom_global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ doom = {
-- @default = true
freeze_dependencies = true,

-- Enables impatent.nvim caching to speed up start time.
-- Can cause more issues so disabled by default
-- @default false
impatient_enabled = false,

-- Autosave
-- false : Disable autosave
-- true : Enable autosave
Expand Down
12 changes: 6 additions & 6 deletions lua/doom/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ if not utils.is_module_enabled("features", "netrw") then
g.loaded_netrwFileHandlers = 1
end

-- Load the colourscheme
profiler.start("framework|doom.core.ui")
utils.safe_require("doom.core.ui")
profiler.stop("framework|doom.core.ui")

-- Set some extra commands
utils.safe_require("doom.core.commands")

profiler.start("framework|doom.core.modules")
-- Load Doom modules.
local modules = utils.safe_require("doom.core.modules")
modules.start()
profiler.start("framework|init enabled modules")
modules.load_modules()
profiler.stop("framework|init enabled modules")
profiler.start("framework|user settings")
modules.handle_user_config()
profiler.stop("framework|user settings")
modules.try_sync()
modules.handle_lazynvim()
profiler.stop("framework|doom.core.modules")

-- Load the colourscheme
profiler.start("framework|doom.core.ui")
utils.safe_require("doom.core.ui")
profiler.stop("framework|doom.core.ui")

-- Execute autocommand for user to hook custom config into
vim.api.nvim_exec_autocmds("User", {
pattern = "DoomStarted",
Expand Down
100 changes: 10 additions & 90 deletions lua/doom/core/modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,95 +31,19 @@ modules.enabled_modules = vim.tbl_deep_extend("keep", core_modules, dofile(modul

local system = require("doom.core.system")

--- Initial bootstrapping of packer including auto-installation if necessary
--- Initial bootstrapping of impatient.nvim
modules.start = function()
if doom.impatient_enabled then
local has_impatient = pcall(require, "impatient")
if not has_impatient then
-- Packer Bootstrapping
local packer_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/impatient.nvim"
if vim.fn.empty(vim.fn.glob(packer_path)) > 0 then
vim.notify("Bootstrapping impatient.nvim, please wait ...")
vim.fn.system({
"git",
"clone",
"--depth",
"1",
"https://github.com/lewis6991/impatient.nvim",
packer_path,
})
end

vim.cmd("packadd impatient.nvim")

require("impatient")
end
end

local has_packer = pcall(require, "packer")
if not has_packer then
modules._needs_sync = true
-- Packer Bootstrapping
local packer_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if vim.fn.empty(vim.fn.glob(packer_path)) > 0 then
vim.notify("Bootstrapping packer.nvim, please wait ...")
vim.fn.system({
"git",
"clone",
"--depth",
"1",
"https://github.com/wbthomason/packer.nvim",
packer_path,
})
end

vim.cmd("packadd packer.nvim")
end

-- Load packer
local packer = require("packer")

-- Change some defaults
-- Of particular interest is compile_path: we use stdpath("data"), so as to not
-- have anything generated in Doom source (which goes in stdpath("config")).
packer.init({
compile_path = system.doom_compile_path,
git = {
clone_timeout = 300, -- 5 mins
subcommands = {
-- Prevent packer from downloading all branches metadata to reduce cloning cost
-- for heavy size plugins like plenary (removed the '--no-single-branch' git flag)
install = "clone --depth %i --progress",
},
},
display = {
open_fn = doom.use_floating_win_packer and function()
return require("packer.util").float({ border = doom.border_style })
end,
},
profile = {
enable = true,
},
log = {
level = doom.logging,
},
})

packer.reset()
end

local keymaps_service = require("doom.services.keymaps")
local commands_service = require("doom.services.commands")
local autocmds_service = require("doom.services.autocommands")

--- Applies commands, autocommands, packages from enabled modules (`modules.lua`).
modules.load_modules = function()
local use = require("packer").use
local logger = require("doom.utils.logging")
-- Handle the Modules
for section_name, _ in pairs(doom.modules) do
for module_name, module in pairs(doom.modules[section_name]) do
if type(module) ~= "table" then
print(("Error on module %s type is %s val is %s"):format(module_name, type(module), module))
end
local profile_msg = ("modules|init `%s.%s`"):format(section_name, module_name)
profiler.start(profile_msg)

Expand Down Expand Up @@ -158,7 +82,7 @@ modules.load_modules = function()
local spec = vim.deepcopy(packer_spec)

-- Set/unset frozen packer dependencies
if type(spec.commit) == "table" then
if type(spec.version) == "table" then
-- Commit can be a table of values, where the keys indicate
-- which neovim version is required.
spec.commit = utils.pick_compatible_field(spec.commit)
Expand All @@ -168,8 +92,8 @@ modules.load_modules = function()
spec.commit = nil
end

-- Initialise packer
use(spec)
-- Save module spec to be initialised later
table.insert(doom.packages, spec)
end
end

Expand Down Expand Up @@ -201,13 +125,6 @@ end

--- Applies user's commands, autocommands, packages from `use_*` helper functions.
modules.handle_user_config = function()
local use = require("packer").use

-- Handle extra user modules
for _, packer_spec in ipairs(doom.packages) do
use(packer_spec)
end

-- Handle extra user cmds
for _, cmd_spec in pairs(doom.cmds) do
commands_service.set(cmd_spec[1], cmd_spec[2], cmd_spec[3] or cmd_spec.opts)
Expand All @@ -233,8 +150,11 @@ modules.try_sync = function()
logger.error("Doom-nvim has been installed. Please restart doom-nvim.")
end,
})
require("packer").sync()
end
end

modules.handle_lazynvim = function()
require("lazy").setup(doom.packages)
end

return modules
23 changes: 2 additions & 21 deletions lua/doom/modules/core/doom/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,16 @@ required.settings = {
}

required.packages = {
["packer.nvim"] = {
"wbthomason/packer.nvim",
},
-- Required by some treesitter modules
["aniseed"] = {
"Olical/aniseed",
commit = "9892a40d4cf970a2916a984544b7f984fc12f55c",
module_pattern = "aniseed",
["lazy.nvim"] = {
"folke/lazy.nvim",
},
["plenary.nvim"] = {
"nvim-lua/plenary.nvim",
commit = "4b7e52044bbb84242158d977a50c4cbcd85070c7",
module = "plenary",
},
["popup.nvim"] = {
"nvim-lua/popup.nvim",
commit = "b7404d35d5d3548a82149238289fa71f7f6de4ac",
module = "popup",
},
["nvim-web-devicons"] = {
"kyazdani42/nvim-web-devicons",
commit = "a8cf88cbdb5c58e2b658e179c4b2aa997479b3da",
module = "nvim-web-devicons",
},
-- Must include impatient.nvim here, even though it's bootstrapped in
-- core.modules.lua so that packer doesn't try and clean it up.
["impatient.nvim"] = {
"lewis6991/impatient.nvim",
disabled = not doom.impatient_enabled,
},
}

Expand Down
6 changes: 4 additions & 2 deletions lua/doom/modules/core/treesitter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@ treesitter.packages = {
"nvim-treesitter/nvim-treesitter",
commit = {
["nvim-0.7"] = "d76b0de6536c2461f97cfeca0550f8cb89793935",
["latest"] = "82767f3f33c903e92f059dc9a2b27ec38dcc28d7",
["latest"] = "be0b3ba1b90b2aa5c78ff7a5798d477a744e5cbe",
},
run = ":TSUpdate",
build = ":TSUpdate",
branch = "master",
},
["nvim-ts-context-commentstring"] = {
"JoosepAlviste/nvim-ts-context-commentstring",
commit = "4d3a68c41a53add8804f471fcc49bb398fe8de08",
after = "nvim-treesitter",
event = "VeryLazy",
},
["nvim-ts-autotag"] = {
"windwp/nvim-ts-autotag",
commit = "fdefe46c6807441460f11f11a167a2baf8e4534b",
after = "nvim-treesitter",
event = "VeryLazy",
},
}

Expand Down
1 change: 0 additions & 1 deletion lua/doom/modules/core/updater/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ updater.packages = {
["plenary.nvim"] = {
"nvim-lua/plenary.nvim",
commit = "4b7e52044bbb84242158d977a50c4cbcd85070c7",
module = "plenary",
},
}

Expand Down
2 changes: 2 additions & 0 deletions lua/doom/modules/features/annotations/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ annotations.packages = {
["neogen"] = {
"danymat/neogen",
commit = "967b280d7d7ade52d97d06e868ec4d9a0bc59282",
keys = { "<leader>cg" },
cmd = "Neogen",
after = "nvim-treesitter",
},
}
Expand Down
1 change: 0 additions & 1 deletion lua/doom/modules/features/auto_session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ auto_session.packages = {
["persistence.nvim"] = {
"folke/persistence.nvim",
commit = "251e89523dabc94242d4a1f2226fc44a95c29d9e",
module = "persistence",
},
}

Expand Down
2 changes: 1 addition & 1 deletion lua/doom/modules/features/autopairs/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ autopairs.packages = {
["nvim-autopairs"] = {
"windwp/nvim-autopairs",
commit = "4fc96c8f3df89b6d23e5092d31c866c53a346347",
event = "BufReadPost",
event = "InsertEnter",
},
}

Expand Down
2 changes: 1 addition & 1 deletion lua/doom/modules/features/colorizer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ colorizer.packages = {
["nvim-colorizer.lua"] = {
"norcalli/nvim-colorizer.lua",
commit = "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6",
event = "WinEnter",
event = "VeryLazy",
},
}

Expand Down
1 change: 0 additions & 1 deletion lua/doom/modules/features/comment/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ comment.packages = {
["Comment.nvim"] = {
"numToStr/Comment.nvim",
commit = "98c81efa6ac1946b63eef685c27f8da928d9f4e7",
module = "Comment",
},
}

Expand Down
1 change: 0 additions & 1 deletion lua/doom/modules/features/dap/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dap.packages = {
["nvim-dap"] = {
"mfussenegger/nvim-dap",
commit = "0b320f5bd4e5f81e8376f9d9681b5c4ee4483c25",
module = "dap",
},
["nvim-dap-ui"] = {
"rcarriga/nvim-dap-ui",
Expand Down
2 changes: 1 addition & 1 deletion lua/doom/modules/features/dashboard/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dashboard.packages = {
"glepnir/dashboard-nvim",
commit = "1676ebeb334a644dd68f7858f9e993602dd8577c",
cmd = "Dashboard",
opt = true,
lazy = true,
},
}

Expand Down
2 changes: 1 addition & 1 deletion lua/doom/modules/features/doom_themes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ doom_themes.packages = {
"GustavoPrietoP/doom-themes.nvim",
commit = "03d417d3eab71c320744f8da22251715ba6cee53",
event = "ColorScheme",
opt = true,
lazy = true,
},
}

Expand Down
1 change: 0 additions & 1 deletion lua/doom/modules/features/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ explorer.packages = {
["nvim-tree.lua"] = {
"kyazdani42/nvim-tree.lua",
commit = "7282f7de8aedf861fe0162a559fc2b214383c51c",
module = "nvim-tree.api",
cmd = {
"NvimTreeClipboard",
"NvimTreeClose",
Expand Down
2 changes: 1 addition & 1 deletion lua/doom/modules/features/extra_snippets/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extra_snippets.settings = {}
extra_snippets.packages = {
["friendly-snippets"] = {
"rafamadriz/friendly-snippets",
after = "LuaSnip",
event = "VeryLazy",
},
}

Expand Down
4 changes: 2 additions & 2 deletions lua/doom/modules/features/firenvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ firenvim.packages = {
["firenvim"] = {
"glacambre/firenvim",
commit = "56a49d79904921a8b4405786e12b4e12fbbf171b",
run = function()
build = function()
vim.fn["firenvim#install"](0)
end,
opt = true,
lazy = true,
},
}

Expand Down
1 change: 1 addition & 0 deletions lua/doom/modules/features/illuminate/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ illuminate.packages = {
["vim-illuminate"] = {
"RRethy/vim-illuminate",
commit = "0603e75fc4ecde1ee5a1b2fc8106ed6704f34d14",
event = "VeryLazy",
},
}

Expand Down
2 changes: 1 addition & 1 deletion lua/doom/modules/features/lazygit/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ lazygit.packages = {
"kdheepak/lazygit.nvim",
commit = "9c73fd69a4c1cb3b3fc35b741ac968e331642600",
cmd = { "LazyGit", "LazyGitConfig" },
opt = true,
lazy = true,
},
}

Expand Down
Loading

3 comments on commit 56c0c3b

@bavalpey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit and subsequent ones breaks installs and really shouldn't have been pushed to the main branch before full testing. Many of the configured lua files are still assuming that packer is the default.
This switch has broken functionality. e.g. the :LspInstall command does not work

@molleweide
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi bavalpey,

We'll to wait for Connor to get back with a reply and see what he has to say.

In the mean time, would you mind explaining what you mean when you say it breaks "install", did you have your own personal branch into which you tried to merge or update, or why did you install the main branch again?

@bavalpey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi bavalpey,

We'll to wait for Connor to get back with a reply and see what he has to say.

In the mean time, would you mind explaining what you mean when you say it breaks "install", did you have your own personal branch into which you tried to merge or update, or why did you install the main branch again?

I did a fresh install as I recently got a new machine. When I say it breaks install, I don't mean that the install process is broken. What I mean is that after a fresh install, the resulting environment is, in large parts, in a broken state. Many of the commands and modules don't work, such as the one I mentioned. Looking briefly through the code, this is due to the remnants of packer in several places. E.g. in features/auto_install/init.lua there are still usages of packadd (and in many other places). A lot of the functionality of Mason.nvim is completely broken. (Install of lsp, dap, etc.).
Let me know if you need additional details.

Please sign in to comment.