Skip to content

Commit 0c6786c

Browse files
committed
feat: use 'rtp' directly instead of using 'packages'
1 parent d85a88c commit 0c6786c

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

‎lua/pack.lua

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ local uv = vim.uv
1111
--- @field status pack.Status?
1212
--- @field hash string?
1313
--- @field pin boolean?
14-
--- @field opt boolean?
1514
--- @field build string? | function?
1615
--- @field url string?
1716

@@ -41,14 +40,11 @@ local Packages = {}
4140
local Path = {
4241
lock = vim.fs.joinpath(vim.fn.stdpath('state'), 'pack-lock.json'),
4342
log = vim.fs.joinpath(vim.fn.stdpath('log'), 'pack.log'),
44-
pack = vim.fs.joinpath(vim.fn.stdpath('data'), 'site', 'pack', 'packs'),
43+
pack = vim.fs.joinpath(vim.fn.stdpath('data'), 'pack'),
4544
}
4645

4746
--- @class pack.Opts
4847
---
49-
--- (default: `false`)
50-
--- @field opt boolean
51-
---
5248
--- (default: `https://github.com/%s.git`)
5349
--- @field url_format string
5450
---
@@ -60,7 +56,6 @@ local Path = {
6056
local Config = {
6157
-- Using '--tags --force' means conflicting tags will be synced with remote
6258
clone_args = { '--depth=1', '--recurse-submodules', '--shallow-submodules', '--no-single-branch' },
63-
opt = false,
6459
pull_args = { '--tags', '--force', '--recurse-submodules', '--update-shallow' },
6560
url_format = 'https://github.com/%s.git',
6661
}
@@ -107,18 +102,15 @@ local function file_read(path)
107102
return data
108103
end
109104

110-
--- @return pack.Package
105+
--- @return pack.Package[]
111106
local function find_unlisted()
112107
local unlisted = {}
113-
for _, packdir in ipairs { 'start', 'opt' } do
114-
local path = vim.fs.joinpath(Path.pack, packdir)
115-
for name, type in vim.fs.dir(path) do
116-
if type == 'directory' and name ~= 'pack.nvim' then
117-
local dir = vim.fs.joinpath(path, name)
118-
local pkg = Packages[name]
119-
if not pkg or pkg.dir ~= dir then
120-
table.insert(unlisted, { name = name, dir = dir })
121-
end
108+
for name, type in vim.fs.dir(Path.pack) do
109+
if type == 'directory' and name ~= 'pack.nvim' then
110+
local dir = vim.fs.joinpath(Path.pack, name)
111+
local pkg = Packages[name]
112+
if not pkg or pkg.dir ~= dir then
113+
table.insert(unlisted, { name = name, dir = dir })
122114
end
123115
end
124116
end
@@ -363,10 +355,10 @@ local function resolve(pkg, counter, build_queue)
363355
end
364356
end
365357

366-
---@param pkg pack.Package
358+
--- @param pkg string|pack.Package
359+
--- @return pack.Package?
367360
local function register(pkg)
368361
if type(pkg) == 'string' then
369-
---@diagnostic disable-next-line: missing-fields
370362
pkg = { pkg }
371363
end
372364

@@ -376,14 +368,14 @@ local function register(pkg)
376368

377369
local name = pkg.as or url:gsub('%.git$', ''):match('/([%w-_.]+)$') -- Infer name from `url`
378370
if not name then
379-
return vim.notify(' Paq: Failed to parse ' .. vim.inspect(pkg), vim.log.levels.ERROR)
371+
error('Pack: Failed to parse ' .. vim.inspect(pkg))
380372
end
381-
local opt = pkg.opt or Config.opt and pkg.opt == nil
382-
local dir = vim.fs.joinpath(Path.pack, (opt and 'opt' or 'start'), name)
373+
374+
local dir = vim.fs.joinpath(Path.pack, name)
383375
local ok, hash = pcall(get_git_hash, dir)
384376
hash = ok and hash or ''
385377

386-
Packages[name] = {
378+
return {
387379
name = name,
388380
branch = pkg.branch,
389381
dir = dir,
@@ -437,7 +429,7 @@ local function exe_op(op, fn, pkgs, silent)
437429
local function after(ok, err, nop)
438430
local summary = 'Pack: %s complete. %d ok; %d errors;' .. (nop > 0 and ' %d no-ops' or '')
439431
vim.notify(string.format(summary, op, ok, err, nop))
440-
vim.cmd('packloadall! | silent! helptags ALL')
432+
vim.cmd('silent! helptags ALL')
441433
if #build_queue ~= 0 then
442434
exe_op('build', run_build, build_queue)
443435
end
@@ -463,7 +455,6 @@ local function calculate_diffs()
463455
local pack_pkg = Packages[name]
464456
if pack_pkg and Filter.not_removed(lock_pkg) and not vim.deep_equal(lock_pkg, pack_pkg) then
465457
for k, v in pairs {
466-
dir = M.status.TO_MOVE,
467458
branch = M.status.TO_RECLONE,
468459
url = M.status.TO_RECLONE,
469460
} do
@@ -495,10 +486,20 @@ end
495486
--- @param pkgs pack.Package[]
496487
function M.register(pkgs)
497488
vim.validate('pkgs', pkgs, 'table', true)
498-
Package = {}
499-
vim.tbl_map(register, pkgs)
489+
Packages = {}
490+
pkgs = vim.tbl_map(register, pkgs)
491+
492+
for _, pkg in ipairs(pkgs) do
493+
Packages[pkg.name] = pkg
494+
vim.opt.runtimepath:prepend(pkg.dir)
495+
end
496+
500497
lock_load()
501498
exe_op('resolve', resolve, calculate_diffs(), true)
499+
500+
for _, pkg in ipairs(find_unlisted()) do
501+
vim.opt.runtimepath:remove(pkg.dir)
502+
end
502503
end
503504

504505
function M.install() exe_op('install', clone, vim.tbl_filter(Filter.to_install, Packages)) end

0 commit comments

Comments
 (0)