Skip to content

Commit dbe2d09

Browse files
committed
feat: plugins no longer need to be installed under site/pack/*/opt
1 parent 37c7366 commit dbe2d09

File tree

6 files changed

+14
-20
lines changed

6 files changed

+14
-20
lines changed

lua/lazy/core/config.lua

+2-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local M = {}
44

55
---@class LazyConfig
66
M.defaults = {
7+
root = vim.fn.stdpath("data") .. "/lazy", -- directory where plugins will be installed
78
defaults = {
89
lazy = false, -- should plugins be loaded at startup?
910
version = nil,
@@ -17,10 +18,6 @@ M.defaults = {
1718
log = { "--since=1 days ago" }, -- commits from the last 3 days
1819
timeout = 120, -- processes taking over 2 minutes will be killed
1920
},
20-
package = {
21-
path = vim.fn.stdpath("data") .. "/site",
22-
name = "lazy", -- plugins will be installed under package.path/pack/{name}/opt
23-
},
2421
-- Any plugin spec that contains one of the patterns will use your
2522
-- local repo in the projects folder instead of fetchig it from github
2623
-- Mostly useful for plugin developers.
@@ -66,9 +63,6 @@ M.ns = vim.api.nvim_create_namespace("lazy")
6663
---@type string|LazySpec Should be either a string pointing to a module, or a spec
6764
M.spec = nil
6865

69-
---@type string Opt directory where plugins will be installed
70-
M.root = nil
71-
7266
---@type table<string, LazyPlugin>
7367
M.plugins = {}
7468

@@ -86,12 +80,8 @@ function M.setup(spec, opts)
8680
M.options.performance.cache = require("lazy.core.cache")
8781
table.insert(M.options.install.colorscheme, "habamax")
8882

89-
M.root = M.options.package.path .. "/pack/" .. M.options.package.name .. "/opt"
90-
9183
if M.options.performance.reset_packpath then
92-
vim.go.packpath = M.options.package.path
93-
else
94-
vim.opt.packpath:prepend(M.options.package.path)
84+
vim.go.packpath = ""
9585
end
9686

9787
vim.api.nvim_create_autocmd("User", {

lua/lazy/core/loader.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ function M.load(plugins, reason)
102102
end
103103

104104
---@param plugin LazyPlugin
105-
function M.packadd(plugin)
105+
---@param force? boolean
106+
function M.packadd(plugin, force)
106107
-- FIXME: investigate further what else is needed
107108
-- vim.cmd.packadd(plugin.name)
108109
-- M.source_runtime(plugin, "/after/plugin")
109-
if M.init_done then
110+
if M.init_done or force then
110111
M.source_runtime(plugin, "/plugin")
111112
if vim.g.did_load_filetypes == 1 then
112113
M.source_runtime(plugin, "/ftdetect")

lua/lazy/core/plugin.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ end
147147
function M.update_state()
148148
---@type table<string,FileType>
149149
local installed = {}
150-
Util.ls(Config.root, function(_, name, type)
150+
Util.ls(Config.options.root, function(_, name, type)
151151
if type == "directory" or type == "link" then
152152
installed[name] = type
153153
end
@@ -169,7 +169,7 @@ function M.update_state()
169169
plugin.dir = plugin.uri
170170
plugin._.installed = true -- user should make sure the directory exists
171171
else
172-
plugin.dir = Config.root .. "/" .. plugin.name
172+
plugin.dir = Config.options.root .. "/" .. plugin.name
173173
plugin._.installed = installed[plugin.name] ~= nil
174174
installed[plugin.name] = nil
175175
end
@@ -179,7 +179,7 @@ function M.update_state()
179179
for pack, dir_type in pairs(installed) do
180180
table.insert(Config.to_clean, {
181181
name = pack,
182-
dir = Config.root .. "/" .. pack,
182+
dir = Config.options.root .. "/" .. pack,
183183
_ = {
184184
installed = true,
185185
is_symlink = dir_type == "link",

lua/lazy/core/util.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function M.try(fn, msg)
4040
end
4141
if info.what ~= "C" and not info.source:find("lazy.nvim") then
4242
local source = info.source:sub(2)
43-
if source:find(Config.root, 1, true) == 1 then
44-
source = source:sub(#Config.root + 1)
43+
if source:find(Config.options.root, 1, true) == 1 then
44+
source = source:sub(#Config.options.root + 1)
4545
end
4646
source = vim.fn.fnamemodify(source, ":p:~:.")
4747
local line = " - " .. source .. ":" .. info.currentline

lua/lazy/manage/task/fs.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ M.clean = {
1010
end,
1111
run = function(self)
1212
local dir = self.plugin.dir:gsub("/+$", "")
13-
assert(dir:find(Config.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")
13+
assert(dir:find(Config.options.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")
1414

1515
local stat = vim.loop.fs_lstat(dir)
1616
assert(stat.type == "directory", self.plugin.dir .. " should be a directory!")

lua/lazy/manage/task/plugin.lua

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ M.build = {
1010
end,
1111
run = function(self)
1212
Loader.load(self.plugin, { task = "build" })
13+
-- when installing during startup, add the package
14+
-- to make sure all runtime files are loaded
15+
Loader.packadd(self.plugin, true)
1316

1417
local build = self.plugin.build
1518
if build then

0 commit comments

Comments
 (0)