mirror of https://github.com/folke/lazy.nvim.git
feat: plugins no longer need to be installed under site/pack/*/opt
This commit is contained in:
parent
37c7366ab0
commit
dbe2d0942a
|
@ -4,6 +4,7 @@ local M = {}
|
||||||
|
|
||||||
---@class LazyConfig
|
---@class LazyConfig
|
||||||
M.defaults = {
|
M.defaults = {
|
||||||
|
root = vim.fn.stdpath("data") .. "/lazy", -- directory where plugins will be installed
|
||||||
defaults = {
|
defaults = {
|
||||||
lazy = false, -- should plugins be loaded at startup?
|
lazy = false, -- should plugins be loaded at startup?
|
||||||
version = nil,
|
version = nil,
|
||||||
|
@ -17,10 +18,6 @@ M.defaults = {
|
||||||
log = { "--since=1 days ago" }, -- commits from the last 3 days
|
log = { "--since=1 days ago" }, -- commits from the last 3 days
|
||||||
timeout = 120, -- processes taking over 2 minutes will be killed
|
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
|
-- Any plugin spec that contains one of the patterns will use your
|
||||||
-- local repo in the projects folder instead of fetchig it from github
|
-- local repo in the projects folder instead of fetchig it from github
|
||||||
-- Mostly useful for plugin developers.
|
-- Mostly useful for plugin developers.
|
||||||
|
@ -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
|
---@type string|LazySpec Should be either a string pointing to a module, or a spec
|
||||||
M.spec = nil
|
M.spec = nil
|
||||||
|
|
||||||
---@type string Opt directory where plugins will be installed
|
|
||||||
M.root = nil
|
|
||||||
|
|
||||||
---@type table<string, LazyPlugin>
|
---@type table<string, LazyPlugin>
|
||||||
M.plugins = {}
|
M.plugins = {}
|
||||||
|
|
||||||
|
@ -86,12 +80,8 @@ function M.setup(spec, opts)
|
||||||
M.options.performance.cache = require("lazy.core.cache")
|
M.options.performance.cache = require("lazy.core.cache")
|
||||||
table.insert(M.options.install.colorscheme, "habamax")
|
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
|
if M.options.performance.reset_packpath then
|
||||||
vim.go.packpath = M.options.package.path
|
vim.go.packpath = ""
|
||||||
else
|
|
||||||
vim.opt.packpath:prepend(M.options.package.path)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("User", {
|
vim.api.nvim_create_autocmd("User", {
|
||||||
|
|
|
@ -102,11 +102,12 @@ function M.load(plugins, reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
function M.packadd(plugin)
|
---@param force? boolean
|
||||||
|
function M.packadd(plugin, force)
|
||||||
-- FIXME: investigate further what else is needed
|
-- FIXME: investigate further what else is needed
|
||||||
-- vim.cmd.packadd(plugin.name)
|
-- vim.cmd.packadd(plugin.name)
|
||||||
-- M.source_runtime(plugin, "/after/plugin")
|
-- M.source_runtime(plugin, "/after/plugin")
|
||||||
if M.init_done then
|
if M.init_done or force then
|
||||||
M.source_runtime(plugin, "/plugin")
|
M.source_runtime(plugin, "/plugin")
|
||||||
if vim.g.did_load_filetypes == 1 then
|
if vim.g.did_load_filetypes == 1 then
|
||||||
M.source_runtime(plugin, "/ftdetect")
|
M.source_runtime(plugin, "/ftdetect")
|
||||||
|
|
|
@ -147,7 +147,7 @@ end
|
||||||
function M.update_state()
|
function M.update_state()
|
||||||
---@type table<string,FileType>
|
---@type table<string,FileType>
|
||||||
local installed = {}
|
local installed = {}
|
||||||
Util.ls(Config.root, function(_, name, type)
|
Util.ls(Config.options.root, function(_, name, type)
|
||||||
if type == "directory" or type == "link" then
|
if type == "directory" or type == "link" then
|
||||||
installed[name] = type
|
installed[name] = type
|
||||||
end
|
end
|
||||||
|
@ -169,7 +169,7 @@ function M.update_state()
|
||||||
plugin.dir = plugin.uri
|
plugin.dir = plugin.uri
|
||||||
plugin._.installed = true -- user should make sure the directory exists
|
plugin._.installed = true -- user should make sure the directory exists
|
||||||
else
|
else
|
||||||
plugin.dir = Config.root .. "/" .. plugin.name
|
plugin.dir = Config.options.root .. "/" .. plugin.name
|
||||||
plugin._.installed = installed[plugin.name] ~= nil
|
plugin._.installed = installed[plugin.name] ~= nil
|
||||||
installed[plugin.name] = nil
|
installed[plugin.name] = nil
|
||||||
end
|
end
|
||||||
|
@ -179,7 +179,7 @@ function M.update_state()
|
||||||
for pack, dir_type in pairs(installed) do
|
for pack, dir_type in pairs(installed) do
|
||||||
table.insert(Config.to_clean, {
|
table.insert(Config.to_clean, {
|
||||||
name = pack,
|
name = pack,
|
||||||
dir = Config.root .. "/" .. pack,
|
dir = Config.options.root .. "/" .. pack,
|
||||||
_ = {
|
_ = {
|
||||||
installed = true,
|
installed = true,
|
||||||
is_symlink = dir_type == "link",
|
is_symlink = dir_type == "link",
|
||||||
|
|
|
@ -40,8 +40,8 @@ function M.try(fn, msg)
|
||||||
end
|
end
|
||||||
if info.what ~= "C" and not info.source:find("lazy.nvim") then
|
if info.what ~= "C" and not info.source:find("lazy.nvim") then
|
||||||
local source = info.source:sub(2)
|
local source = info.source:sub(2)
|
||||||
if source:find(Config.root, 1, true) == 1 then
|
if source:find(Config.options.root, 1, true) == 1 then
|
||||||
source = source:sub(#Config.root + 1)
|
source = source:sub(#Config.options.root + 1)
|
||||||
end
|
end
|
||||||
source = vim.fn.fnamemodify(source, ":p:~:.")
|
source = vim.fn.fnamemodify(source, ":p:~:.")
|
||||||
local line = " - " .. source .. ":" .. info.currentline
|
local line = " - " .. source .. ":" .. info.currentline
|
||||||
|
|
|
@ -10,7 +10,7 @@ M.clean = {
|
||||||
end,
|
end,
|
||||||
run = function(self)
|
run = function(self)
|
||||||
local dir = self.plugin.dir:gsub("/+$", "")
|
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)
|
local stat = vim.loop.fs_lstat(dir)
|
||||||
assert(stat.type == "directory", self.plugin.dir .. " should be a directory!")
|
assert(stat.type == "directory", self.plugin.dir .. " should be a directory!")
|
||||||
|
|
|
@ -10,6 +10,9 @@ M.build = {
|
||||||
end,
|
end,
|
||||||
run = function(self)
|
run = function(self)
|
||||||
Loader.load(self.plugin, { task = "build" })
|
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
|
local build = self.plugin.build
|
||||||
if build then
|
if build then
|
||||||
|
|
Loading…
Reference in New Issue