diff --git a/.github/workflows/luarocks.yml b/.github/workflows/luarocks.yml index 951a52a1..94663d8d 100644 --- a/.github/workflows/luarocks.yml +++ b/.github/workflows/luarocks.yml @@ -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 diff --git a/bootstrap.lua b/bootstrap.lua index 0666d69e..4fa2765c 100644 --- a/bootstrap.lua +++ b/bootstrap.lua @@ -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 @@ -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...") diff --git a/doc/rocks.txt b/doc/rocks.txt index 5f5527a3..d98caac8 100644 --- a/doc/rocks.txt +++ b/doc/rocks.txt @@ -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. diff --git a/installer.lua b/installer.lua index 1c696897..22cab0a5 100644 --- a/installer.lua +++ b/installer.lua @@ -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 @@ -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", @@ -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", @@ -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", diff --git a/lua/rocks/config/init.lua b/lua/rocks/config/init.lua index e63d0b56..1f2fcae1 100644 --- a/lua/rocks/config/init.lua +++ b/lua/rocks/config/init.lua @@ -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. diff --git a/lua/rocks/config/internal.lua b/lua/rocks/config/internal.lua index ce547454..9beee45a 100644 --- a/lua/rocks/config/internal.lua +++ b/lua/rocks/config/internal.lua @@ -21,17 +21,19 @@ local config = {} local constants = require("rocks.constants") local fs = require("rocks.fs") +---@diagnostic disable-next-line: param-type-mismatch +local default_rocks_path = vim.fs.joinpath(vim.fn.stdpath("data"), "rocks") + --- rocks.nvim default configuration ---@class RocksConfig local default_config = { ---@type string Local path in your filesystem to install rocks - ---@diagnostic disable-next-line: param-type-mismatch - rocks_path = vim.fs.joinpath(vim.fn.stdpath("data"), "rocks"), + rocks_path = default_rocks_path, ---@type string Rocks declaration file path ---@diagnostic disable-next-line: param-type-mismatch config_path = vim.fs.joinpath(vim.fn.stdpath("config"), "rocks.toml"), ---@type string Luarocks binary path - luarocks_binary = "luarocks", + luarocks_binary = vim.fs.joinpath(default_rocks_path, "bin", "luarocks"), ---@type boolean Whether to query luarocks.org lazily lazy = false, ---@type boolean Whether to automatically add freshly installed plugins to the 'runtimepath' @@ -91,6 +93,12 @@ config = vim.tbl_deep_extend("force", { }, default_config, opts) ---@cast config RocksConfig +if not opts.luarocks_binary then + --- luarocks_binary has not been overridden. Set it in case rocks_path has. + ---@diagnostic disable-next-line: inject-field + config.luarocks_binary = vim.fs.joinpath(config.rocks_path, "bin", "luarocks") +end + local ok, err = check.validate(config) if not ok then vim.notify("Rocks: " .. err, vim.log.levels.ERROR) diff --git a/nix/test-overlay.nix b/nix/test-overlay.nix index cd0a27c7..5b3106be 100644 --- a/nix/test-overlay.nix +++ b/nix/test-overlay.nix @@ -8,6 +8,7 @@ neovim = nvim; luaPackages = ps: with ps; [ + luarocks toml-edit toml fidget-nvim diff --git a/rocks.nvim-scm-1.rockspec b/rocks.nvim-scm-1.rockspec index 4bcaad11..ece794d0 100644 --- a/rocks.nvim-scm-1.rockspec +++ b/rocks.nvim-scm-1.rockspec @@ -8,6 +8,7 @@ version = _MODREV .. _SPECREV dependencies = { "lua >= 5.1", + "luarocks >= 3.8.0, < 4.0.0", "toml-edit >= 0.3.6", "fidget.nvim >= 1.1.0", "fzy",