Skip to content

Commit

Permalink
feat: manage luarocks installation as rockspec dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed May 30, 2024
1 parent e52cfb8 commit 342e763
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 90 deletions.
1 change: 1 addition & 0 deletions .github/workflows/luarocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
version: ${{ env.LUAROCKS_VERSION }}
test_interpreters: ""
dependencies: |
luarocks >= 3.11.0, < 4.0.0
toml-edit >= 0.3.6
fidget.nvim >= 1.1.0
fzy
Expand Down
7 changes: 5 additions & 2 deletions bootstrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ math.randomseed(os.time())

local config_data = vim.g.rocks_nvim or {}
local install_path = config_data.rocks_path or vim.fs.joinpath(vim.fn.stdpath("data") --[[@as string]], "rocks")
local luarocks_binary = config_data.luarocks_binary or vim.fs.joinpath(install_path, "bin", "luarocks")
local temp_luarocks_path =
---@diagnostic disable-next-line: param-type-mismatch
vim.fs.joinpath(vim.fn.stdpath("run"), ("luarocks-%X"):format(math.random(256 ^ 7)))
local luarocks_binary = vim.fs.joinpath(temp_luarocks_path, "bin", "luarocks")

---@param dep string
---@return boolean is_missing
Expand Down Expand Up @@ -104,7 +107,7 @@ local function set_up_luarocks(path)
return true
end

assert(set_up_luarocks(install_path), "failed to install luarocks! Please try again :)")
assert(set_up_luarocks(temp_luarocks_path), "failed to install luarocks! Please try again :)")

vim.notify("Installing rocks.nvim...")

Expand Down
2 changes: 1 addition & 1 deletion doc/rocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ RocksOpts *RocksOpts*
Fields: ~
{rocks_path?} (string) Local path in your filesystem to install rocks. Defaults to a `rocks` directory in `vim.fn.stdpath("data")`.
{config_path?} (string) Rocks declaration file path. Defaults to `rocks.toml` in `vim.fn.stdpath("config")`.
{luarocks_binary?} (string) Luarocks binary path. Defaults to `luarocks`.
{luarocks_binary?} (string) Luarocks binary path. Defaults to `{rocks_path}/bin/luarocks`.
{lazy?} (boolean) Whether to query luarocks.org lazily. Defaults to `false`. Setting this to `true` may improve startup time, but features like auto-completion will lag initially.
{dynamic_rtp?} (boolean) Whether to automatically add freshly installed plugins to the 'runtimepath'. Defaults to `true` for the best default experience.
{generate_help_pages?} (boolean) Whether to re-generate plugins help pages after installation/upgrade.
Expand Down
144 changes: 69 additions & 75 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,18 @@ local function install()
if line == "< OK >" then
local install_path = input_fields.install_path.content
local setup_luarocks = input_fields.setup_luarocks.content == "true"
local temp_luarocks_path =
---@diagnostic disable-next-line: param-type-mismatch
vim.fs.joinpath(vim.fn.stdpath("run"), ("luarocks-%X"):format(math.random(256 ^ 7)))

local luarocks_binary = "luarocks"

if setup_luarocks then
local success = set_up_luarocks(install_path)
local success = set_up_luarocks(temp_luarocks_path)
if not success then
return
end
luarocks_binary = vim.fs.joinpath(install_path, "bin", "luarocks")
luarocks_binary = vim.fs.joinpath(temp_luarocks_path, "bin", "luarocks")
elseif vim.fn.executable(luarocks_binary) ~= 1 then
vim.notify(
luarocks_binary
Expand Down Expand Up @@ -389,7 +392,6 @@ local function install()

acquire_buffer_lock(buffer, function()
local install_path_rel = install_path:gsub(vim.env.HOME, "")
local luarocks_binary_rel = luarocks_binary:gsub(vim.env.HOME, "")

vim.api.nvim_buf_set_lines(buffer, 0, -1, true, {
"INSTALLATION COMPLETE",
Expand All @@ -399,7 +401,6 @@ local function install()
">lua",
" local rocks_config = {",
' rocks_path = vim.env.HOME .. "' .. install_path_rel .. '",',
' luarocks_binary = vim.env.HOME .. "' .. luarocks_binary_rel .. '",',
" }",
" ",
" vim.g.rocks_nvim = rocks_config",
Expand Down Expand Up @@ -437,7 +438,6 @@ local function install()
vim.fn.setreg('"', {
"local rocks_config = {",
' rocks_path = vim.env.HOME .. "' .. install_path_rel .. '",',
' luarocks_binary = vim.env.HOME .. "' .. luarocks_binary_rel .. '",',
"}",
"",
"vim.g.rocks_nvim = rocks_config",
Expand Down
2 changes: 1 addition & 1 deletion lua/rocks/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local config = {}
---@class RocksOpts
---@field rocks_path? string Local path in your filesystem to install rocks. Defaults to a `rocks` directory in `vim.fn.stdpath("data")`.
---@field config_path? string Rocks declaration file path. Defaults to `rocks.toml` in `vim.fn.stdpath("config")`.
---@field luarocks_binary? string Luarocks binary path. Defaults to `luarocks`.
---@field luarocks_binary? string Luarocks binary path. Defaults to `{rocks_path}/bin/luarocks`.
---@field lazy? boolean Whether to query luarocks.org lazily. Defaults to `false`. Setting this to `true` may improve startup time, but features like auto-completion will lag initially.
---@field dynamic_rtp? boolean Whether to automatically add freshly installed plugins to the 'runtimepath'. Defaults to `true` for the best default experience.
---@field generate_help_pages? boolean Whether to re-generate plugins help pages after installation/upgrade.
Expand Down
Loading

0 comments on commit 342e763

Please sign in to comment.