@@ -61,43 +61,48 @@ function Spec.new(spec)
61
61
return self
62
62
end
63
63
64
+ -- PERF: optimized code to get package name without using lua patterns
65
+ function Spec .get_name (pkg )
66
+ local name = pkg :sub (- 4 ) == " .git" and pkg :sub (1 , - 5 ) or pkg
67
+ local slash = name :reverse ():find (" /" , 1 , true ) --[[ @as number?]]
68
+ return slash and name :sub (# name - slash + 2 ) or pkg :gsub (" %W+" , " _" )
69
+ end
70
+
64
71
--- @param plugin LazyPlugin
65
72
--- @param is_dep ? boolean
66
73
function Spec :add (plugin , is_dep )
67
- local pkg = plugin [1 ]
68
- if type (pkg ) ~= " string" then
69
- Util .error (" Invalid plugin spec " .. vim .inspect (plugin ))
74
+ if not plugin .url and plugin [1 ] then
75
+ plugin .url = Config .options .git .url_format :format (plugin [1 ])
70
76
end
71
77
72
- if not plugin .url then
73
- local c = pkg :sub (1 , 1 )
74
- if c == " ~" then
75
- plugin .url = vim .loop .os_getenv (" HOME" ) .. pkg :sub (2 )
76
- elseif c == " /" or pkg :sub (1 , 4 ) == " http" or pkg :sub (1 , 3 ) == " ssh" then
77
- plugin .url = pkg
78
+ if plugin .dir then
79
+ -- local plugin
80
+ plugin .name = plugin .name or Spec .get_name (plugin .dir )
81
+ elseif plugin .url then
82
+ plugin .name = plugin .name or Spec .get_name (plugin .url )
83
+ -- check for dev plugins
84
+ if plugin .dev == nil then
85
+ for _ , pattern in ipairs (Config .options .dev .patterns ) do
86
+ if plugin .url :find (pattern , 1 , true ) then
87
+ plugin .dev = true
88
+ break
89
+ end
90
+ end
91
+ end
92
+ -- dev plugins
93
+ if plugin .dev then
94
+ plugin .dir = Config .options .dev .path .. " /" .. plugin .name
78
95
else
79
- plugin .url = (" https://github.com/" .. pkg .. " .git" )
96
+ -- remote plugin
97
+ plugin .dir = Config .options .root .. " /" .. plugin .name
80
98
end
81
- end
82
-
83
- -- PERF: optimized code to get package name without using lua patterns
84
- if not plugin .name then
85
- local name = pkg :sub (- 4 ) == " .git" and pkg :sub (1 , - 5 ) or pkg
86
- local slash = name :reverse ():find (" /" , 1 , true ) --[[ @as number?]]
87
- plugin .name = slash and name :sub (# name - slash + 2 ) or pkg :gsub (" %W+" , " _" )
99
+ else
100
+ Util .error (" Invalid plugin spec " .. vim .inspect (plugin ))
88
101
end
89
102
90
103
plugin ._ = {}
91
104
plugin ._ .dep = is_dep
92
105
93
- -- check for plugins that should be local
94
- for _ , pattern in ipairs (Config .options .dev .patterns ) do
95
- if plugin .dev or (plugin [1 ]:find (pattern , 1 , true ) and plugin .dev ~= false ) then
96
- plugin .url = Config .options .dev .path .. " /" .. plugin .name
97
- break
98
- end
99
- end
100
-
101
106
local other = self .plugins [plugin .name ]
102
107
self .plugins [plugin .name ] = other and self :merge (other , plugin ) or plugin
103
108
return self .plugins [plugin .name ]
@@ -171,14 +176,12 @@ function M.update_state()
171
176
or plugin .cmd
172
177
plugin .lazy = lazy and true or false
173
178
end
174
- if plugin .url :sub (1 , 4 ) ~= " http" and plugin .url :sub (1 , 3 ) ~= " git" then
175
- plugin ._ .is_local = true
176
- plugin .dir = plugin .url
177
- plugin ._ .installed = true -- user should make sure the directory exists
178
- else
179
- plugin .dir = Config .options .root .. " /" .. plugin .name
179
+ if plugin .dir :find (Config .options .root ) == 1 then
180
180
plugin ._ .installed = installed [plugin .name ] ~= nil
181
181
installed [plugin .name ] = nil
182
+ else
183
+ plugin ._ .is_local = true
184
+ plugin ._ .installed = true -- local plugins are managed by the user
182
185
end
183
186
end
184
187
0 commit comments