feat!: local plugins now always need to set `Plugin.dir`

This commit is contained in:
Folke Lemaitre 2022-12-13 10:09:33 +01:00
parent 2a7466abad
commit 0625493aad
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 36 additions and 32 deletions

View File

@ -17,6 +17,7 @@ M.defaults = {
-- log = { "-10" }, -- last 10 commits -- log = { "-10" }, -- last 10 commits
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
url_format = "https://github.com/%s.git",
}, },
-- 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

View File

@ -61,43 +61,48 @@ function Spec.new(spec)
return self return self
end end
-- PERF: optimized code to get package name without using lua patterns
function Spec.get_name(pkg)
local name = pkg:sub(-4) == ".git" and pkg:sub(1, -5) or pkg
local slash = name:reverse():find("/", 1, true) --[[@as number?]]
return slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_")
end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
---@param is_dep? boolean ---@param is_dep? boolean
function Spec:add(plugin, is_dep) function Spec:add(plugin, is_dep)
local pkg = plugin[1] if not plugin.url and plugin[1] then
if type(pkg) ~= "string" then plugin.url = Config.options.git.url_format:format(plugin[1])
Util.error("Invalid plugin spec " .. vim.inspect(plugin))
end end
if not plugin.url then if plugin.dir then
local c = pkg:sub(1, 1) -- local plugin
if c == "~" then plugin.name = plugin.name or Spec.get_name(plugin.dir)
plugin.url = vim.loop.os_getenv("HOME") .. pkg:sub(2) elseif plugin.url then
elseif c == "/" or pkg:sub(1, 4) == "http" or pkg:sub(1, 3) == "ssh" then plugin.name = plugin.name or Spec.get_name(plugin.url)
plugin.url = pkg -- check for dev plugins
else if plugin.dev == nil then
plugin.url = ("https://github.com/" .. pkg .. ".git") for _, pattern in ipairs(Config.options.dev.patterns) do
if plugin.url:find(pattern, 1, true) then
plugin.dev = true
break
end
end
end end
end -- dev plugins
if plugin.dev then
-- PERF: optimized code to get package name without using lua patterns plugin.dir = Config.options.dev.path .. "/" .. plugin.name
if not plugin.name then else
local name = pkg:sub(-4) == ".git" and pkg:sub(1, -5) or pkg -- remote plugin
local slash = name:reverse():find("/", 1, true) --[[@as number?]] plugin.dir = Config.options.root .. "/" .. plugin.name
plugin.name = slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_") end
else
Util.error("Invalid plugin spec " .. vim.inspect(plugin))
end end
plugin._ = {} plugin._ = {}
plugin._.dep = is_dep plugin._.dep = is_dep
-- check for plugins that should be local
for _, pattern in ipairs(Config.options.dev.patterns) do
if plugin.dev or (plugin[1]:find(pattern, 1, true) and plugin.dev ~= false) then
plugin.url = Config.options.dev.path .. "/" .. plugin.name
break
end
end
local other = self.plugins[plugin.name] local other = self.plugins[plugin.name]
self.plugins[plugin.name] = other and self:merge(other, plugin) or plugin self.plugins[plugin.name] = other and self:merge(other, plugin) or plugin
return self.plugins[plugin.name] return self.plugins[plugin.name]
@ -171,14 +176,12 @@ function M.update_state()
or plugin.cmd or plugin.cmd
plugin.lazy = lazy and true or false plugin.lazy = lazy and true or false
end end
if plugin.url:sub(1, 4) ~= "http" and plugin.url:sub(1, 3) ~= "git" then if plugin.dir:find(Config.options.root) == 1 then
plugin._.is_local = true
plugin.dir = plugin.url
plugin._.installed = true -- user should make sure the directory exists
else
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
else
plugin._.is_local = true
plugin._.installed = true -- local plugins are managed by the user
end end
end end