Skip to content

Commit

Permalink
(feat)luarocks: make rocks path configurable; fixes #672
Browse files Browse the repository at this point in the history
  • Loading branch information
msva committed Jul 3, 2022
1 parent d268d2e commit 987cabc
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions lua/packer/luarocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ local fmt = string.format
local async = a.sync
local await = a.wait

local config = nil
local function cfg(_config)
config = _config.luarocks
end
local function warn_need_luajit()
log.error 'LuaJIT is required for Luarocks functionality!'
end
Expand All @@ -40,11 +36,34 @@ else
}
end

local cache_path = vim.fn.stdpath 'cache'
local rocks_path = util.join_paths(cache_path, 'packer_hererocks')
local hererocks_file = util.join_paths(rocks_path, 'hererocks.py')
local hererocks_install_dir = util.join_paths(rocks_path, lua_version.dir)
local shell_hererocks_dir = vim.fn.shellescape(hererocks_install_dir)
local config = nil
local cache_path = nil
local rocks_path = nil
local hererocks_file = nil
local hererocks_install_dir = nil
local shell_hererocks_dir = nil

local function package_patterns(dir)
local sep = util.get_separator()
return fmt('%s%s?.lua;%s%s?%sinit.lua', dir, sep, dir, sep, sep)
end

local package_paths = nil

local function cfg(_config)
config = _config.luarocks
cache_path = config.cache_path or vim.fn.stdpath 'cache'
rocks_path = config.rocks_path or util.join_paths(cache_path, 'packer_hererocks')
hererocks_file = config.hererocks_file or util.join_paths(rocks_path, 'hererocks.py')
hererocks_install_dir = config.hererocks_install_dir or util.join_paths(rocks_path, lua_version.dir)
shell_hererocks_dir = config.shell_hererocks_dir or vim.fn.shellescape(hererocks_install_dir)
package_paths = (function()
local install_path = util.join_paths(hererocks_install_dir, 'lib', 'luarocks', fmt('rocks-%s', lua_version.lua))
local share_path = util.join_paths(hererocks_install_dir, 'share', 'lua', lua_version.lua)
return package_patterns(share_path) .. ';' .. package_patterns(install_path)
end)()
end

local _hererocks_setup_done = false
local function hererocks_is_setup()
if _hererocks_setup_done then
Expand Down Expand Up @@ -108,17 +127,6 @@ local function hererocks_installer(disp)
end)
end

local function package_patterns(dir)
local sep = util.get_separator()
return fmt('%s%s?.lua;%s%s?%sinit.lua', dir, sep, dir, sep, sep)
end

local package_paths = (function()
local install_path = util.join_paths(hererocks_install_dir, 'lib', 'luarocks', fmt('rocks-%s', lua_version.lua))
local share_path = util.join_paths(hererocks_install_dir, 'share', 'lua', lua_version.lua)
return package_patterns(share_path) .. ';' .. package_patterns(install_path)
end)()

local nvim_paths_are_setup = false
local function setup_nvim_paths()
if not hererocks_is_setup() then
Expand Down

0 comments on commit 987cabc

Please sign in to comment.