Skip to content

Commit

Permalink
feat: plugins no longer need to be installed under site/pack/*/opt
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 3, 2022
1 parent 37c7366 commit dbe2d09
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
14 changes: 2 additions & 12 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local M = {}

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

---@type string Opt directory where plugins will be installed
M.root = nil

---@type table<string, LazyPlugin>
M.plugins = {}

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

M.root = M.options.package.path .. "/pack/" .. M.options.package.name .. "/opt"

if M.options.performance.reset_packpath then
vim.go.packpath = M.options.package.path
else
vim.opt.packpath:prepend(M.options.package.path)
vim.go.packpath = ""
end

vim.api.nvim_create_autocmd("User", {
Expand Down
5 changes: 3 additions & 2 deletions lua/lazy/core/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ function M.load(plugins, reason)
end

---@param plugin LazyPlugin
function M.packadd(plugin)
---@param force? boolean
function M.packadd(plugin, force)
-- FIXME: investigate further what else is needed
-- vim.cmd.packadd(plugin.name)
-- M.source_runtime(plugin, "/after/plugin")
if M.init_done then
if M.init_done or force then
M.source_runtime(plugin, "/plugin")
if vim.g.did_load_filetypes == 1 then
M.source_runtime(plugin, "/ftdetect")
Expand Down
6 changes: 3 additions & 3 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ end
function M.update_state()
---@type table<string,FileType>
local installed = {}
Util.ls(Config.root, function(_, name, type)
Util.ls(Config.options.root, function(_, name, type)
if type == "directory" or type == "link" then
installed[name] = type
end
Expand All @@ -169,7 +169,7 @@ function M.update_state()
plugin.dir = plugin.uri
plugin._.installed = true -- user should make sure the directory exists
else
plugin.dir = Config.root .. "/" .. plugin.name
plugin.dir = Config.options.root .. "/" .. plugin.name
plugin._.installed = installed[plugin.name] ~= nil
installed[plugin.name] = nil
end
Expand All @@ -179,7 +179,7 @@ function M.update_state()
for pack, dir_type in pairs(installed) do
table.insert(Config.to_clean, {
name = pack,
dir = Config.root .. "/" .. pack,
dir = Config.options.root .. "/" .. pack,
_ = {
installed = true,
is_symlink = dir_type == "link",
Expand Down
4 changes: 2 additions & 2 deletions lua/lazy/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function M.try(fn, msg)
end
if info.what ~= "C" and not info.source:find("lazy.nvim") then
local source = info.source:sub(2)
if source:find(Config.root, 1, true) == 1 then
source = source:sub(#Config.root + 1)
if source:find(Config.options.root, 1, true) == 1 then
source = source:sub(#Config.options.root + 1)
end
source = vim.fn.fnamemodify(source, ":p:~:.")
local line = " - " .. source .. ":" .. info.currentline
Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/manage/task/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ M.clean = {
end,
run = function(self)
local dir = self.plugin.dir:gsub("/+$", "")
assert(dir:find(Config.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")
assert(dir:find(Config.options.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")

local stat = vim.loop.fs_lstat(dir)
assert(stat.type == "directory", self.plugin.dir .. " should be a directory!")
Expand Down
3 changes: 3 additions & 0 deletions lua/lazy/manage/task/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ M.build = {
end,
run = function(self)
Loader.load(self.plugin, { task = "build" })
-- when installing during startup, add the package
-- to make sure all runtime files are loaded
Loader.packadd(self.plugin, true)

local build = self.plugin.build
if build then
Expand Down

0 comments on commit dbe2d09

Please sign in to comment.