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

Commit 56c0c3b

Browse files
author
connorgmeean
committed
refact: Switch to lazy.nvim and improve lazy loading
1 parent df6b2c6 commit 56c0c3b

File tree

38 files changed

+76
-161
lines changed

38 files changed

+76
-161
lines changed

init.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ end
1313
local profiler = require("doom.services.profiler")
1414
profiler.start("framework|init.lua")
1515

16+
-- Preload lazy nvim
17+
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
18+
if not vim.loop.fs_stat(lazypath) then
19+
print("Bootstrapping lazy.nvim, please wait...")
20+
vim.fn.system({
21+
"git",
22+
"clone",
23+
"--filter=blob:none",
24+
"https://github.com/folke/lazy.nvim.git",
25+
"--branch=stable", -- latest stable release
26+
lazypath,
27+
})
28+
end
29+
vim.opt.rtp:prepend(lazypath)
1630

1731
-- Makes sure ~/.local/share/nvim exists, to prevent problems with logging
1832
vim.fn.mkdir(vim.fn.stdpath("data"), "p")

lua/doom/core/doom_global.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ doom = {
6060
-- @default = true
6161
freeze_dependencies = true,
6262

63-
-- Enables impatent.nvim caching to speed up start time.
64-
-- Can cause more issues so disabled by default
65-
-- @default false
66-
impatient_enabled = false,
67-
6863
-- Autosave
6964
-- false : Disable autosave
7065
-- true : Enable autosave

lua/doom/core/init.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,27 @@ if not utils.is_module_enabled("features", "netrw") then
4949
g.loaded_netrwFileHandlers = 1
5050
end
5151

52-
-- Load the colourscheme
53-
profiler.start("framework|doom.core.ui")
54-
utils.safe_require("doom.core.ui")
55-
profiler.stop("framework|doom.core.ui")
56-
5752
-- Set some extra commands
5853
utils.safe_require("doom.core.commands")
5954

6055
profiler.start("framework|doom.core.modules")
6156
-- Load Doom modules.
6257
local modules = utils.safe_require("doom.core.modules")
63-
modules.start()
6458
profiler.start("framework|init enabled modules")
6559
modules.load_modules()
6660
profiler.stop("framework|init enabled modules")
6761
profiler.start("framework|user settings")
6862
modules.handle_user_config()
6963
profiler.stop("framework|user settings")
7064
modules.try_sync()
65+
modules.handle_lazynvim()
7166
profiler.stop("framework|doom.core.modules")
7267

68+
-- Load the colourscheme
69+
profiler.start("framework|doom.core.ui")
70+
utils.safe_require("doom.core.ui")
71+
profiler.stop("framework|doom.core.ui")
72+
7373
-- Execute autocommand for user to hook custom config into
7474
vim.api.nvim_exec_autocmds("User", {
7575
pattern = "DoomStarted",

lua/doom/core/modules.lua

Lines changed: 10 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -31,95 +31,19 @@ modules.enabled_modules = vim.tbl_deep_extend("keep", core_modules, dofile(modul
3131

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

34-
--- Initial bootstrapping of packer including auto-installation if necessary
35-
--- Initial bootstrapping of impatient.nvim
36-
modules.start = function()
37-
if doom.impatient_enabled then
38-
local has_impatient = pcall(require, "impatient")
39-
if not has_impatient then
40-
-- Packer Bootstrapping
41-
local packer_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/impatient.nvim"
42-
if vim.fn.empty(vim.fn.glob(packer_path)) > 0 then
43-
vim.notify("Bootstrapping impatient.nvim, please wait ...")
44-
vim.fn.system({
45-
"git",
46-
"clone",
47-
"--depth",
48-
"1",
49-
"https://github.com/lewis6991/impatient.nvim",
50-
packer_path,
51-
})
52-
end
53-
54-
vim.cmd("packadd impatient.nvim")
55-
56-
require("impatient")
57-
end
58-
end
59-
60-
local has_packer = pcall(require, "packer")
61-
if not has_packer then
62-
modules._needs_sync = true
63-
-- Packer Bootstrapping
64-
local packer_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
65-
if vim.fn.empty(vim.fn.glob(packer_path)) > 0 then
66-
vim.notify("Bootstrapping packer.nvim, please wait ...")
67-
vim.fn.system({
68-
"git",
69-
"clone",
70-
"--depth",
71-
"1",
72-
"https://github.com/wbthomason/packer.nvim",
73-
packer_path,
74-
})
75-
end
76-
77-
vim.cmd("packadd packer.nvim")
78-
end
79-
80-
-- Load packer
81-
local packer = require("packer")
82-
83-
-- Change some defaults
84-
-- Of particular interest is compile_path: we use stdpath("data"), so as to not
85-
-- have anything generated in Doom source (which goes in stdpath("config")).
86-
packer.init({
87-
compile_path = system.doom_compile_path,
88-
git = {
89-
clone_timeout = 300, -- 5 mins
90-
subcommands = {
91-
-- Prevent packer from downloading all branches metadata to reduce cloning cost
92-
-- for heavy size plugins like plenary (removed the '--no-single-branch' git flag)
93-
install = "clone --depth %i --progress",
94-
},
95-
},
96-
display = {
97-
open_fn = doom.use_floating_win_packer and function()
98-
return require("packer.util").float({ border = doom.border_style })
99-
end,
100-
},
101-
profile = {
102-
enable = true,
103-
},
104-
log = {
105-
level = doom.logging,
106-
},
107-
})
108-
109-
packer.reset()
110-
end
111-
11234
local keymaps_service = require("doom.services.keymaps")
11335
local commands_service = require("doom.services.commands")
11436
local autocmds_service = require("doom.services.autocommands")
11537

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

@@ -158,7 +82,7 @@ modules.load_modules = function()
15882
local spec = vim.deepcopy(packer_spec)
15983

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

171-
-- Initialise packer
172-
use(spec)
95+
-- Save module spec to be initialised later
96+
table.insert(doom.packages, spec)
17397
end
17498
end
17599

@@ -201,13 +125,6 @@ end
201125

202126
--- Applies user's commands, autocommands, packages from `use_*` helper functions.
203127
modules.handle_user_config = function()
204-
local use = require("packer").use
205-
206-
-- Handle extra user modules
207-
for _, packer_spec in ipairs(doom.packages) do
208-
use(packer_spec)
209-
end
210-
211128
-- Handle extra user cmds
212129
for _, cmd_spec in pairs(doom.cmds) do
213130
commands_service.set(cmd_spec[1], cmd_spec[2], cmd_spec[3] or cmd_spec.opts)
@@ -233,8 +150,11 @@ modules.try_sync = function()
233150
logger.error("Doom-nvim has been installed. Please restart doom-nvim.")
234151
end,
235152
})
236-
require("packer").sync()
237153
end
238154
end
239155

156+
modules.handle_lazynvim = function()
157+
require("lazy").setup(doom.packages)
158+
end
159+
240160
return modules

lua/doom/modules/core/doom/init.lua

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,16 @@ required.settings = {
55
}
66

77
required.packages = {
8-
["packer.nvim"] = {
9-
"wbthomason/packer.nvim",
10-
},
11-
-- Required by some treesitter modules
12-
["aniseed"] = {
13-
"Olical/aniseed",
14-
commit = "9892a40d4cf970a2916a984544b7f984fc12f55c",
15-
module_pattern = "aniseed",
8+
["lazy.nvim"] = {
9+
"folke/lazy.nvim",
1610
},
1711
["plenary.nvim"] = {
1812
"nvim-lua/plenary.nvim",
1913
commit = "4b7e52044bbb84242158d977a50c4cbcd85070c7",
20-
module = "plenary",
21-
},
22-
["popup.nvim"] = {
23-
"nvim-lua/popup.nvim",
24-
commit = "b7404d35d5d3548a82149238289fa71f7f6de4ac",
25-
module = "popup",
2614
},
2715
["nvim-web-devicons"] = {
2816
"kyazdani42/nvim-web-devicons",
2917
commit = "a8cf88cbdb5c58e2b658e179c4b2aa997479b3da",
30-
module = "nvim-web-devicons",
31-
},
32-
-- Must include impatient.nvim here, even though it's bootstrapped in
33-
-- core.modules.lua so that packer doesn't try and clean it up.
34-
["impatient.nvim"] = {
35-
"lewis6991/impatient.nvim",
36-
disabled = not doom.impatient_enabled,
3718
},
3819
}
3920

lua/doom/modules/core/treesitter/init.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,22 @@ treesitter.packages = {
4848
"nvim-treesitter/nvim-treesitter",
4949
commit = {
5050
["nvim-0.7"] = "d76b0de6536c2461f97cfeca0550f8cb89793935",
51-
["latest"] = "82767f3f33c903e92f059dc9a2b27ec38dcc28d7",
51+
["latest"] = "be0b3ba1b90b2aa5c78ff7a5798d477a744e5cbe",
5252
},
53-
run = ":TSUpdate",
53+
build = ":TSUpdate",
5454
branch = "master",
5555
},
5656
["nvim-ts-context-commentstring"] = {
5757
"JoosepAlviste/nvim-ts-context-commentstring",
5858
commit = "4d3a68c41a53add8804f471fcc49bb398fe8de08",
5959
after = "nvim-treesitter",
60+
event = "VeryLazy",
6061
},
6162
["nvim-ts-autotag"] = {
6263
"windwp/nvim-ts-autotag",
6364
commit = "fdefe46c6807441460f11f11a167a2baf8e4534b",
6465
after = "nvim-treesitter",
66+
event = "VeryLazy",
6567
},
6668
}
6769

lua/doom/modules/core/updater/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ updater.packages = {
2525
["plenary.nvim"] = {
2626
"nvim-lua/plenary.nvim",
2727
commit = "4b7e52044bbb84242158d977a50c4cbcd85070c7",
28-
module = "plenary",
2928
},
3029
}
3130

lua/doom/modules/features/annotations/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ annotations.packages = {
2020
["neogen"] = {
2121
"danymat/neogen",
2222
commit = "967b280d7d7ade52d97d06e868ec4d9a0bc59282",
23+
keys = { "<leader>cg" },
24+
cmd = "Neogen",
2325
after = "nvim-treesitter",
2426
},
2527
}

lua/doom/modules/features/auto_session/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ auto_session.packages = {
88
["persistence.nvim"] = {
99
"folke/persistence.nvim",
1010
commit = "251e89523dabc94242d4a1f2226fc44a95c29d9e",
11-
module = "persistence",
1211
},
1312
}
1413

lua/doom/modules/features/autopairs/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ autopairs.packages = {
1010
["nvim-autopairs"] = {
1111
"windwp/nvim-autopairs",
1212
commit = "4fc96c8f3df89b6d23e5092d31c866c53a346347",
13-
event = "BufReadPost",
13+
event = "InsertEnter",
1414
},
1515
}
1616

lua/doom/modules/features/colorizer/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ colorizer.packages = {
1010
["nvim-colorizer.lua"] = {
1111
"norcalli/nvim-colorizer.lua",
1212
commit = "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6",
13-
event = "WinEnter",
13+
event = "VeryLazy",
1414
},
1515
}
1616

lua/doom/modules/features/comment/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ comment.packages = {
4545
["Comment.nvim"] = {
4646
"numToStr/Comment.nvim",
4747
commit = "98c81efa6ac1946b63eef685c27f8da928d9f4e7",
48-
module = "Comment",
4948
},
5049
}
5150

lua/doom/modules/features/dap/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ dap.packages = {
3939
["nvim-dap"] = {
4040
"mfussenegger/nvim-dap",
4141
commit = "0b320f5bd4e5f81e8376f9d9681b5c4ee4483c25",
42-
module = "dap",
4342
},
4443
["nvim-dap-ui"] = {
4544
"rcarriga/nvim-dap-ui",

lua/doom/modules/features/dashboard/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ dashboard.packages = {
6969
"glepnir/dashboard-nvim",
7070
commit = "1676ebeb334a644dd68f7858f9e993602dd8577c",
7171
cmd = "Dashboard",
72-
opt = true,
72+
lazy = true,
7373
},
7474
}
7575

lua/doom/modules/features/doom_themes/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ doom_themes.packages = {
99
"GustavoPrietoP/doom-themes.nvim",
1010
commit = "03d417d3eab71c320744f8da22251715ba6cee53",
1111
event = "ColorScheme",
12-
opt = true,
12+
lazy = true,
1313
},
1414
}
1515

lua/doom/modules/features/explorer/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ explorer.packages = {
9595
["nvim-tree.lua"] = {
9696
"kyazdani42/nvim-tree.lua",
9797
commit = "7282f7de8aedf861fe0162a559fc2b214383c51c",
98-
module = "nvim-tree.api",
9998
cmd = {
10099
"NvimTreeClipboard",
101100
"NvimTreeClose",

lua/doom/modules/features/extra_snippets/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extra_snippets.settings = {}
55
extra_snippets.packages = {
66
["friendly-snippets"] = {
77
"rafamadriz/friendly-snippets",
8-
after = "LuaSnip",
8+
event = "VeryLazy",
99
},
1010
}
1111

lua/doom/modules/features/firenvim/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ firenvim.packages = {
2626
["firenvim"] = {
2727
"glacambre/firenvim",
2828
commit = "56a49d79904921a8b4405786e12b4e12fbbf171b",
29-
run = function()
29+
build = function()
3030
vim.fn["firenvim#install"](0)
3131
end,
32-
opt = true,
32+
lazy = true,
3333
},
3434
}
3535

lua/doom/modules/features/illuminate/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ illuminate.packages = {
1717
["vim-illuminate"] = {
1818
"RRethy/vim-illuminate",
1919
commit = "0603e75fc4ecde1ee5a1b2fc8106ed6704f34d14",
20+
event = "VeryLazy",
2021
},
2122
}
2223

lua/doom/modules/features/lazygit/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ lazygit.packages = {
77
"kdheepak/lazygit.nvim",
88
commit = "9c73fd69a4c1cb3b3fc35b741ac968e331642600",
99
cmd = { "LazyGit", "LazyGitConfig" },
10-
opt = true,
10+
lazy = true,
1111
},
1212
}
1313

0 commit comments

Comments
 (0)