-
Notifications
You must be signed in to change notification settings - Fork 431
bug: No autoload on require when username is lua #1981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
See failed to run config for lualine.nvim on starting NeoVim in |
I unfortunately had to close PR #1982, as it broke existing behavior... |
Hey @abeldekat I thought of something but not sure at all if it works. Could you try something along these lines diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua
index 1501efd..bdcbc38 100644
--- a/lua/lazy/core/loader.lua
+++ b/lua/lazy/core/loader.lua
@@ -529,7 +529,7 @@ function M.colorscheme(name)
end
function M.auto_load(modname, modpath)
- local plugin = Plugin.find(modpath, { fast = not M.did_handlers })
+ local plugin = Plugin.find(modpath, modname, { fast = not M.did_handlers })
if plugin then
plugin._.rtp_loaded = true
-- don't load if:
diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua
index 37d1a8f..2981785 100644
--- a/lua/lazy/core/plugin.lua
+++ b/lua/lazy/core/plugin.lua
@@ -384,13 +384,16 @@ end
-- Finds the plugin that has this path
---@param path string
+---@param modname? string
---@param opts? {fast?:boolean}
-function M.find(path, opts)
+function M.find(path, modname, opts)
if not Config.spec then
return
end
opts = opts or {}
- local lua = path:find("/lua/", 1, true)
+ local topmod = Util.topmod(modname)
+ local modlocation = path:find(topmod, 1, true)
+ local lua = path:find("/lua/", modlocation + 1, true)
if lua then
local name = path:sub(1, lua - 1)
local slash = name:reverse():find("/", 1, true) So, basically change the Please keep in mind I might just be spewing total non-sense. PS: I didn't write the extra conditional check for if PS2: I made wrong assumption that |
Hi @dpetka2001, thanks for the suggestions! I created the PR under the incorrect assumption that the text "lua" would by convention only be used in the root level of a plugin. Unfortunately I do not know the code well enough to provide or comment on alternatives. |
Hi @abeldekat would you be willing to test the following patch diff --git a/lua/lazy/core/loader.lua b/lua/lazy/core/loader.lua
index 1501efd..bdcbc38 100644
--- a/lua/lazy/core/loader.lua
+++ b/lua/lazy/core/loader.lua
@@ -529,7 +529,7 @@ function M.colorscheme(name)
end
function M.auto_load(modname, modpath)
- local plugin = Plugin.find(modpath, { fast = not M.did_handlers })
+ local plugin = Plugin.find(modpath, modname, { fast = not M.did_handlers })
if plugin then
plugin._.rtp_loaded = true
-- don't load if:
diff --git a/lua/lazy/core/plugin.lua b/lua/lazy/core/plugin.lua
index 37d1a8f..0ac2bbf 100644
--- a/lua/lazy/core/plugin.lua
+++ b/lua/lazy/core/plugin.lua
@@ -384,23 +384,44 @@ end
-- Finds the plugin that has this path
---@param path string
+---@param modname? string
---@param opts? {fast?:boolean}
-function M.find(path, opts)
+function M.find(path, modname, opts)
if not Config.spec then
return
end
opts = opts or {}
- local lua = path:find("/lua/", 1, true)
- if lua then
- local name = path:sub(1, lua - 1)
- local slash = name:reverse():find("/", 1, true)
- if slash then
- name = name:sub(#name - slash + 2)
- if name then
- if opts.fast then
- return Config.spec.meta.plugins[name]
+ if modname then
+ local topmod = Util.topmod(modname)
+ local reversed = path:reverse()
+ local topreversed = topmod:reverse()
+ local topreversed_loc = reversed:find(topreversed, 1, true)
+ local rev_start, rev_end = reversed:find("/aul/", topreversed_loc + 1, true)
+ if rev_start then
+ local rev_next_slash = reversed:find("/", rev_end + 1, true)
+ if rev_next_slash then
+ local name = path:sub(#path - rev_next_slash +2, #path - rev_end)
+ if name then
+ if opts.fast then
+ return Config.spec.meta.plugins[name]
+ end
+ return Config.spec.plugins[name]
+ end
+ end
+ end
+ else
+ local lua = path:find("/lua/", 1, true)
+ if lua then
+ local name = path:sub(1, lua - 1)
+ local slash = name:reverse():find("/", 1, true)
+ if slash then
+ name = name:sub(#name - slash + 2)
+ if name then
+ if opts.fast then
+ return Config.spec.meta.plugins[name]
+ end
+ return Config.spec.plugins[name]
end
- return Config.spec.plugins[name]
end
end
end |
I think it might work, and thus still isn't good enough...) It's a tough issue to fix in my opinion. I gathered some of my thoughts, which of cause still suffer from a lack of deep inside knowledge... Markers in the code: A plugin on disk has the following path: Outside/N/"lua"/Inner, where:
The existing code for "find" implicitly assumes that there is no "lua" folder in Outside. As a consequence, no assumptions are needed on the organization in Inside. The code can discard that tail when trying to find the name of the plugin. My PR, and your code as well, now does make assumptions on Inside, because unfortunately, a user can be named "lua" in Outside. Other situations I can think of:
When an assumption on Inside does not hold true that might lead to bugs that are very difficult to solve. A good fix would eliminate assumptions. As suggested by @Phanen:
A solution will need to be performant. Closing the issue as a "known limitation" is also a possibility perhaps. |
Thank you for your insight. Indeed if there's another But I agree that we make too many assumptions and a better solution should be in place if at all. This all started from a rather niche case of the username being |
Did you check docs and existing issues?
Neovim version (nvim -v)
0.11.0
Operating system/version
Arch linux
Describe the bug
user_is_lua.mp4
When the username is "lua",
lazy.nvim
silently fails to autoload a plugin onrequire
Steps To Reproduce
Setup:
Reproduce:
Type:
:lua require("lualine")
and enterTeardown:
exit sudo userdel lua rm -rf /home/lua
Expected Behavior
Normally, given the supplied
repro
, lualine would appear after typing:lua require("lualine")
and enter.Repro
The text was updated successfully, but these errors were encountered: