Skip to content
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

bug: Utils.has does not work as expected for non-lazy users #1041

Open
JeanMertz opened this issue Jan 5, 2025 · 1 comment
Open

bug: Utils.has does not work as expected for non-lazy users #1041

JeanMertz opened this issue Jan 5, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@JeanMertz
Copy link

Describe the bug

The implementation of Utils.has is as follows:

---Check if a plugin is installed
---@param plugin string
---@return boolean
M.has = function(plugin)
local ok, LazyConfig = pcall(require, "lazy.core.config")
if ok then return LazyConfig.plugins[plugin] ~= nil end
return package.loaded[plugin] ~= nil
end

For non-lazy.nvim users this checks if the provided module is part of the package.loaded table.

However, a module is only inserted into this table after it has been required, but it's possible that avante.nvim is loaded before the specified module to has has been required, but that module might still be in the runtimepath and thus is accessible if needed.

I believe :h runtime-search-path provides a better alternative, specifically:

-- List all runtime dirs and packages with Lua paths.
nvim_get_runtime_file("lua/", v:true)

To reproduce

No response

Expected behavior

No response

Installation method

n/a

Environment

n/a

Repro

No response

@JeanMertz JeanMertz added the bug Something isn't working label Jan 5, 2025
@JeanMertz
Copy link
Author

I should note, I ran into this due to :checkhealth throwing errors that weren't accurate:

-- Required dependencies
local required_plugins = {
["nvim-treesitter"] = "nvim-treesitter/nvim-treesitter",
["dressing.nvim"] = "stevearc/dressing.nvim",
["plenary.nvim"] = "nvim-lua/plenary.nvim",
["nui.nvim"] = "MunifTanjim/nui.nvim",
}
for plugin_name, plugin_path in pairs(required_plugins) do
if Utils.has(plugin_name) then
H.ok(string.format("Found required plugin: %s", plugin_path))
else
H.error(string.format("Missing required plugin: %s", plugin_path))
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant