Skip to content

Commit

Permalink
feat: added support for luarocks installed with lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 26, 2024
1 parent 6184ebb commit e3d0d55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/lazydev/buf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ function M.on_mod(buf, modname)
if path then
ws:add(path)
end
else
local modpath = Pkg.find_rock(modname)
if modpath then
ws:add(modpath)
end
end
end

Expand Down
18 changes: 18 additions & 0 deletions lua/lazydev/pkg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ function M.get_plugin_path(name)
end
end

function M.find_rock(modname)
if not is_lazy then
return
end
local Config = require("lazy.core.config")
for _, plugin in pairs(Config.spec.plugins) do
if plugin._.pkg and plugin._.pkg.source == "rockspec" then
local root = Config.options.rocks.root .. "/" .. plugin.name
root = root .. "/share/lua/5.1"
for _, p in ipairs({ "/init.lua", ".lua" }) do
if vim.uv.fs_stat(root .. "/" .. modname:gsub("%.", "/") .. p) then
return root
end
end
end
end
end

---@param modname string
---@return string[]
function M.find_roots(modname)
Expand Down

0 comments on commit e3d0d55

Please sign in to comment.