-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
lazy.lua
104 lines (78 loc) · 2.83 KB
/
lazy.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
local util = require('one.util')
local pUtil = require('one.plugin-manager.util')
local P = {}
P.cmds = { install = ':Lazy install<CR>', status = ':Lazy home<CR>' }
-- Some fields is ignored. Because PluginManager has implemented these functions.
local fields = {
-- LuaFormatter off
--[[ 'config','dependencies', ]]
rtp = 'dir', 'url', 'name', 'dev', 'lazy', 'enabled', 'cond', setup = 'init', 'opts',
run = 'build', 'branch', tag = 'version', 'commit', 'version', 'pin', 'submodules',
'event', 'cmd', 'ft', 'keys', 'module', 'priority',
-- LuaFormatter on
}
local function parseOpts(repo, opts)
local plugOpts = pUtil.parseOpts(fields, opts, { repo })
local deps = {}
for _, depPkg in pairs(opts.requires or {}) do
if depPkg.repo then deps[#deps + 1] = util.getRepoName(depPkg.repo) end
end
for _, depPkg in pairs(opts.deps or {}) do
if depPkg.repo then deps[#deps + 1] = util.getRepoName(depPkg.repo) end
end
if not vim.tbl_isempty(deps) then plugOpts.dependencies = deps end
return plugOpts
end
local errorNotify
-- Lazy.nvim always notify "Plugin ... is not installed" on startup.
-- https://github.com/folke/lazy.nvim/blob/f8611632d0f9c6818e8eb54f9bcd1dad122b5a7f/lua/lazy/core/loader.lua#L297
-- I want to trigger the notification via nvim-notify after startup.
local function silentNotifyPluginUninstall()
local lazyUtil = require('lazy.core.util')
errorNotify = lazyUtil.error
lazyUtil.error = function(msg, opts)
if not string.match(msg, '^Plugin [-._a-zA-Z0-9]+ is not installed$') then errorNotify(msg, opts) end
end
end
local function unsilentNotifyPluginUninstall()
local lazyUtil = require('lazy.core.util')
lazyUtil.error = errorNotify
end
-- @param params see lua/one/plugin-manager/init.lua
function P.setup(params)
local config = params.config
local lazyOpts = config.pluginManager.lazy
local lazyConfig = lazyOpts.config
local isNew = util.ensurePkg { -- ensure packer.nvim downloaded
url = lazyOpts.src,
dist = lazyOpts.dist,
branch = lazyOpts.srcBranch,
}
-- if isNew then util.packadd(lazyOpts.dist) end
vim.opt.rtp:prepend(lazyOpts.dist)
lazyConfig.git.url_format = util.proxyGithub(lazyConfig.git.url_format)
local lazy = require('lazy')
silentNotifyPluginUninstall()
local plugins = {}
P.loadPlug = function(repo, opts)
local plugOpts = parseOpts(repo, opts)
plugins[#plugins + 1] = plugOpts
end
P.lazyConfig = lazyConfig
vim.keymap.set('n', '<SPACE>P', P.cmds.status, { desc = 'Show Plugin Status' })
params.loadPlugs()
vim.api.nvim_create_autocmd('User', {
pattern = 'LazyDone',
callback = function()
-- The packer compiled file is already loaded by PackerSync
params.run(isNew)
end,
})
lazy.setup(plugins, lazyConfig)
unsilentNotifyPluginUninstall()
return isNew
end
function P.getPluginFolderPath(folderName)
return util.pathJoin(P.lazyConfig.root, folderName)
end
return P