Skip to content

Commit

Permalink
refactor: migrate to lazy.nvim (LunarVim#3647)
Browse files Browse the repository at this point in the history
* refactor: convert plugins spec to lazy

* refactor(lazy): remove impatient

* fix(telescope): no more errors if theme is nil

* refactor(lazy): use lazy in plugin_loader

* refactor(lazy): pin plugins with packer's snapshot

* fix: add plugins to rtp before config:init

* fix: fs_stat nil check

* feat: lazy cache

* feat(lazy): reloading

* refactor(lazy): plugin-loader functions

* feat(lazy): cache reset

* refactor: set runtimepath manually

* fix: runtimepath

* refactor(rtp)

* refactor(lazy): packer -> lazy in various places

* fix(lazy): disable tree-sitter ensure installed

* refactor(lazy): restore order to bootstrap

* refactor(lazy): remove unused impatient profiler

* small fixes

* `lvim.plugins` deprecation handling

* fix: deprecation of `requires` in plugin specs

* feat: core plugins pinning

* refactor(lazy): plugin loader tests

* refactor(lazy): use lazy in scripts

* refactor(lazy): which-key keybinds

* chore: format

* fix: installer

* fix: first time setup

* feat: changes required for packaging

commit 951ac2b
Author: LostNeophyte <[email protected]>
Date:   Wed Dec 28 13:49:44 2022 +0100

    fix: clean folder before copying plugins

commit 64e9afa
Author: LostNeophyte <[email protected]>
Date:   Wed Dec 28 13:35:41 2022 +0100

    feat: copy core plugins on first run

commit 2d8e720
Author: LostNeophyte <[email protected]>
Date:   Wed Dec 28 13:11:22 2022 +0100

    feat(utils): fs_copy

commit 85c1f02
Author: LostNeophyte <[email protected]>
Date:   Wed Dec 28 13:04:38 2022 +0100

    fix: copy correct example config

* fix: packer specs deprecation handling

* fix: plugin specs deprecation

* feat: pin lazy's version

* fix: remove plugins form rtp before loading lazy

* fix: plugin-loader test

* feat(lazy): add keymappings for profile, log, and debug (LunarVim#3665)

* feat(lazy): Add keymappings for profile, log, and debug

* feat(lazy): Add keymap for cleaning

* chore: format

* pref: lazy load many plugins

Co-authored-by: Uzair Aftab <[email protected]>

* fix: bootstrap correct version of lazy

* fix: also use CmdLineEnter event for cmp

* fix: don't use lazy's modules before it's set up

* perf: (hack) enable lazy's cache before loading lazy

* fix: plugins.lua

* fix: plugins bump script

* chore: remove debug print

* feat: add rounded border for `:Lazy`

* fix: bufferline flashing

* fix: don't close lazy on startup

* fix: load breadcrumbs on startup

* fix: don't lazy load bufferline

* chore: bump lazy's version

* fix: remove site from rtp (fixes treesitter issues)

* revert default config copying changes

* fix(bootstrap): actually remove plugins dir on windows

* chore: bump lazy's version

* chore: bump lazy's version

Co-authored-by: kylo252 <[email protected]>
Co-authored-by: Uzair Aftab <[email protected]>
Co-authored-by: Uzair Aftab <[email protected]>
Co-authored-by: opalmay <[email protected]>
  • Loading branch information
5 people authored Jan 10, 2023
1 parent fc68738 commit ccb80e4
Show file tree
Hide file tree
Showing 26 changed files with 377 additions and 1,081 deletions.
27 changes: 11 additions & 16 deletions lua/lvim/bootstrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local M = {}
if vim.fn.has "nvim-0.8" ~= 1 then
vim.notify("Please upgrade your Neovim base installation. Lunarvim requires v0.8+", vim.log.levels.WARN)
vim.wait(5000, function()
---@diagnostic disable-next-line: redundant-return-value
return false
end)
vim.cmd "cquit"
Expand All @@ -23,7 +24,7 @@ _G.require_safe = require("lvim.utils.modules").require_safe
_G.reload = require("lvim.utils.modules").reload

---Get the full path to `$LUNARVIM_RUNTIME_DIR`
---@return string
---@return string|nil
function _G.get_runtime_dir()
local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR"
if not lvim_runtime_dir then
Expand All @@ -34,7 +35,7 @@ function _G.get_runtime_dir()
end

---Get the full path to `$LUNARVIM_CONFIG_DIR`
---@return string
---@return string|nil
function _G.get_config_dir()
local lvim_config_dir = os.getenv "LUNARVIM_CONFIG_DIR"
if not lvim_config_dir then
Expand All @@ -44,7 +45,7 @@ function _G.get_config_dir()
end

---Get the full path to `$LUNARVIM_CACHE_DIR`
---@return string
---@return string|nil
function _G.get_cache_dir()
local lvim_cache_dir = os.getenv "LUNARVIM_CACHE_DIR"
if not lvim_cache_dir then
Expand All @@ -60,11 +61,11 @@ function M:init(base_dir)
self.config_dir = get_config_dir()
self.cache_dir = get_cache_dir()
self.pack_dir = join_paths(self.runtime_dir, "site", "pack")
self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim")
self.packer_cache_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua")
self.lazy_install_dir = join_paths(self.pack_dir, "lazy", "opt", "lazy.nvim")

---@meta overridden to use LUNARVIM_CACHE_DIR instead, since a lot of plugins call this function internally
---NOTE: changes to "data" are currently unstable, see #2507
---@diagnostic disable-next-line: duplicate-set-field
vim.fn.stdpath = function(what)
if what == "cache" then
return _G.get_cache_dir()
Expand All @@ -79,33 +80,27 @@ function M:init(base_dir)
end

if os.getenv "LUNARVIM_RUNTIME_DIR" then
-- vim.opt.rtp:append(os.getenv "LUNARVIM_RUNTIME_DIR" .. path_sep .. "lvim")
vim.opt.rtp:remove(join_paths(vim.call("stdpath", "data"), "site"))
vim.opt.rtp:remove(join_paths(vim.call("stdpath", "data"), "site", "after"))
vim.opt.rtp:prepend(join_paths(self.runtime_dir, "site"))
-- vim.opt.rtp:prepend(join_paths(self.runtime_dir, "site"))
vim.opt.rtp:append(join_paths(self.runtime_dir, "lvim", "after"))
vim.opt.rtp:append(join_paths(self.runtime_dir, "site", "after"))

vim.opt.rtp:remove(vim.call("stdpath", "config"))
vim.opt.rtp:remove(join_paths(vim.call("stdpath", "config"), "after"))
vim.opt.rtp:prepend(self.config_dir)
vim.opt.rtp:append(join_paths(self.config_dir, "after"))
-- TODO: we need something like this: vim.opt.packpath = vim.opt.rtp

vim.cmd [[let &packpath = &runtimepath]]
end

if not vim.env.LVIM_TEST_ENV then
require "lvim.impatient"
vim.opt.packpath = vim.opt.rtp:get()
end

require("lvim.config"):init()

require("lvim.plugin-loader").init {
package_root = self.pack_dir,
install_path = self.packer_install_dir,
install_path = self.lazy_install_dir,
}

require("lvim.config"):init()

require("lvim.core.mason").bootstrap()

return self
Expand Down
101 changes: 88 additions & 13 deletions lua/lvim/config/_deprecated.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ function M.handle()
end,
})

---@deprecated
lvim.builtin.dashboard = {}
setmetatable(lvim.builtin.dashboard, {
__newindex = function(_, k, _)
deprecate("lvim.builtin.dashboard." .. k, "Use `lvim.builtin.alpha` instead. See LunarVim#1906")
end,
})

---@deprecated
lvim.lsp.popup_border = {}
setmetatable(lvim.lsp.popup_border, mt)

---@deprecated
lvim.lang = {}
setmetatable(lvim.lang, mt)
end

function M.post_load()
if lvim.lsp.override and not vim.tbl_isempty(lvim.lsp.override) then
deprecate("lvim.lsp.override", "Use `lvim.lsp.automatic_configuration.skipped_servers` instead")
vim.tbl_map(function(c)
Expand All @@ -64,21 +82,78 @@ function M.handle()
)
end

---@deprecated
lvim.builtin.dashboard = {}
setmetatable(lvim.builtin.dashboard, {
__newindex = function(_, k, _)
deprecate("lvim.builtin.dashboard." .. k, "Use `lvim.builtin.alpha` instead. See LunarVim#1906")
end,
})
local function convert_spec_to_lazy(spec)
local alternatives = {
setup = "init",
as = "name",
opt = "lazy",
run = "build",
lock = "pin",
tag = "version",
}

---@deprecated
lvim.lsp.popup_border = {}
setmetatable(lvim.lsp.popup_border, mt)
alternatives.requires = function()
if type(spec.requires) == "string" then
spec.dependencies = { spec.requires }
else
spec.dependencies = spec.requires
end

---@deprecated
lvim.lang = {}
setmetatable(lvim.lang, mt)
return "Use `dependencies` instead"
end

alternatives.disable = function()
if type(spec.disabled) == "function" then
spec.enabled = function()
return not spec.disabled()
end
else
spec.enabled = not spec.disabled
end
return "Use `enabled` instead"
end

alternatives.wants = function()
return "It's not needed in most cases, otherwise use `dependencies`."
end
alternatives.needs = alternatives.wants

alternatives.module = function()
spec.lazy = true
return "Use `lazy = true` instead."
end

for old_key, alternative in pairs(alternatives) do
if spec[old_key] ~= nil then
local message

if type(alternative) == "function" then
message = alternative()
else
spec[alternative] = spec[old_key]
end
spec[old_key] = nil

message = message or string.format("Use `%s` instead.", alternative)
deprecate(
string.format("%s` in `lvim.plugins", old_key),
message .. " See https://github.com/folke/lazy.nvim#-migration-guide"
)
end
end

if spec[1] and spec[1]:match "^http" then
spec.url = spec[1]
spec[1] = nil
deprecate("{ 'http...' }` in `lvim.plugins", "Use { url = 'http...' } instead.")
end
end

for _, plugin in ipairs(lvim.plugins) do
if type(plugin) == "table" then
convert_spec_to_lazy(plugin)
end
end
end

return M
2 changes: 2 additions & 0 deletions lua/lvim/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ function M:load(config_path)

Log:set_level(lvim.log.level)

require("lvim.config._deprecated").post_load()

autocmds.define_autocmds(lvim.autocommands)

vim.g.mapleader = (lvim.leader == "space" and " ") or lvim.leader
Expand Down
2 changes: 1 addition & 1 deletion lua/lvim/core/breadcrumbs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ M.config = function()
"help",
"startify",
"dashboard",
"packer",
"lazy",
"neo-tree",
"neogitstatus",
"NvimTree",
Expand Down
4 changes: 2 additions & 2 deletions lua/lvim/core/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ M.config = function()
highlight = "PanelHeading",
},
{
filetype = "packer",
text = "Packer",
filetype = "lazy",
text = "Lazy",
highlight = "PanelHeading",
padding = 1,
},
Expand Down
2 changes: 1 addition & 1 deletion lua/lvim/core/illuminate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ M.config = function()
"fugitive",
"alpha",
"NvimTree",
"packer",
"lazy",
"neogitstatus",
"Trouble",
"lir",
Expand Down
2 changes: 1 addition & 1 deletion lua/lvim/core/indentlines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ M.config = function()
"help",
"startify",
"dashboard",
"packer",
"lazy",
"neogitstatus",
"NvimTree",
"Trouble",
Expand Down
7 changes: 0 additions & 7 deletions lua/lvim/core/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ function Log:set_level(level)
s.level = log_level
end
end

local packer_ok, _ = xpcall(function()
require("packer.log").cfg { log = { level = level } }
end, debug.traceback)
if not packer_ok then
vim.notify_once("Unable to set packer's log level to " .. level)
end
end

function Log:init()
Expand Down
2 changes: 1 addition & 1 deletion lua/lvim/core/nvimtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function M.config()
picker = "default",
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
filetype = { "notify", "lazy", "qf", "diff", "fugitive", "fugitiveblame" },
buftype = { "nofile", "terminal", "help" },
},
},
Expand Down
21 changes: 9 additions & 12 deletions lua/lvim/core/which-key.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ M.config = function()
U = { "<cmd>lua require'dapui'.toggle({reset = true})<cr>", "Toggle UI" },
},
p = {
name = "Packer",
c = { "<cmd>PackerCompile<cr>", "Compile" },
i = { "<cmd>PackerInstall<cr>", "Install" },
r = { "<cmd>lua require('lvim.plugin-loader').recompile()<cr>", "Re-compile" },
s = { "<cmd>PackerSync<cr>", "Sync" },
S = { "<cmd>PackerStatus<cr>", "Status" },
u = { "<cmd>PackerUpdate<cr>", "Update" },
name = "Plugins",
i = { "<cmd>Lazy install<cr>", "Install" },
s = { "<cmd>Lazy sync<cr>", "Sync" },
S = { "<cmd>Lazy clear<cr>", "Status" },
c = { "<cmd>Lazy clean<cr>", "Clean" },
u = { "<cmd>Lazy update<cr>", "Update" },
p = { "<cmd>Lazy profile<cr>", "Profile" },
l = { "<cmd>Lazy log<cr>", "Log" },
d = { "<cmd>Lazy debug<cr>", "Debug" },
},

-- " Available Debug Adapters:
Expand Down Expand Up @@ -268,11 +270,6 @@ M.config = function()
"view neovim log",
},
N = { "<cmd>edit $NVIM_LOG_FILE<cr>", "Open the Neovim logfile" },
p = {
"<cmd>lua require('lvim.core.terminal').toggle_log_view(get_cache_dir() .. '/packer.nvim.log')<cr>",
"view packer log",
},
P = { "<cmd>edit $LUNARVIM_CACHE_DIR/packer.nvim.log<cr>", "Open the Packer logfile" },
},
r = { "<cmd>LvimReload<cr>", "Reload LunarVim's configuration" },
u = { "<cmd>LvimUpdate<cr>", "Update LunarVim" },
Expand Down
Loading

0 comments on commit ccb80e4

Please sign in to comment.