Skip to content

Commit

Permalink
fix(loader): add entire luarocks lua path (#248)
Browse files Browse the repository at this point in the history
* fix(loader): add entire luarocks lua path

* chore(loader): reduce failure notification level to warn
  • Loading branch information
mrcjkb authored Apr 7, 2024
1 parent e2bf447 commit 0d041ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion nix/plugin-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ in {
-- Copied from installer.lua
local rocks_config = {
rocks_path = vim.fn.stdpath("data") .. "/rocks",
luarocks_binary = "${final.luarocks}/bin/luarocks",
luarocks_binary = "${final.lua51Packages.luarocks}/bin/luarocks",
}
vim.g.rocks_nvim = rocks_config
Expand Down
24 changes: 15 additions & 9 deletions plugin/rocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ local nio = require("nio")
local adapter = require("rocks.adapter")
local config = require("rocks.config.internal")

local function get_luarocks_loader_path_from_luarocks()
local sc = vim.system({ config.luarocks_binary, "which", "luarocks.loader" }):wait()
return sc.stdout and sc.stdout:match("(%S+)loader.lua")
local function get_luarocks_lua_dir_from_luarocks()
local sc = vim.system({ config.luarocks_binary, "--lua-version=5.1", "which", "luarocks.loader" }):wait()
local result = sc.stdout and sc.stdout:match(vim.fs.joinpath("(%S+)", "luarocks", "loader.lua"))
return result
end

-- Initialize the luarocks loader
if config.enable_luarocks_loader then
local default_luarocks_binary = vim.fs.joinpath(config.rocks_path, "bin", "luarocks")
local luarocks_loader_path = config.luarocks_binary == default_luarocks_binary
and vim.fs.joinpath(default_luarocks_binary, "share", "lua", "5.1", "luarocks", "?.lua")
or get_luarocks_loader_path_from_luarocks()
if luarocks_loader_path then
package.path = package.path .. ";" .. luarocks_loader_path .. "?.lua"
local luarocks_lua_dir = config.luarocks_binary == default_luarocks_binary
and vim.fs.joinpath(default_luarocks_binary, "share", "lua", "5.1")
or get_luarocks_lua_dir_from_luarocks()
if luarocks_lua_dir then
package.path = package.path
.. ";"
.. table.concat({
vim.fs.joinpath(luarocks_lua_dir, "?.lua"),
vim.fs.joinpath(luarocks_lua_dir, "init.lua"),
}, ";")
vim.env.LUAROCKS_CONFIG = config.luarocks_config
local ok, err = pcall(require, "luarocks.loader")
-- TODO: log errors
if not ok then
vim.notify("Failed to initialize luarocks loader: " .. err, vim.log.levels.ERROR, {
vim.notify("Failed to initialize luarocks loader: " .. err, vim.log.levels.WARN, {
title = "rocks.nvim",
})
end
Expand Down

0 comments on commit 0d041ec

Please sign in to comment.