Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow overriding luarocks config #334

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions doc/rocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ rocks.nvim configuration *rocks.config*
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`.
{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.
{reinstall_dev_rocks_on_update} (boolean) Whether to reinstall 'dev' rocks on update (Default: `true`, as rocks.nvim cannot determine if 'dev' rocks are up to date).
{enable_luarocks_loader} (boolean) Whether to use the luarocks loader to support multiple dependencies (Default: `true`)
{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`.
{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.
{reinstall_dev_rocks_on_update?} (boolean) Whether to reinstall 'dev' rocks on update (Default: `true`, as rocks.nvim cannot determine if 'dev' rocks are up to date).
{enable_luarocks_loader?} (boolean) Whether to use the luarocks loader to support multiple dependencies (Default: `true`)
{luarocks_config?} (string) Path to the luarocks config. If not set, rocks.nvim will create one in `rocks_path`. Warning: You should include the settings in the default luarocks-config.lua before overriding this.


==============================================================================
Expand Down
5 changes: 3 additions & 2 deletions lua/rocks/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ local config = {}
---@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.
---@field reinstall_dev_rocks_on_update boolean Whether to reinstall 'dev' rocks on update (Default: `true`, as rocks.nvim cannot determine if 'dev' rocks are up to date).
---@field enable_luarocks_loader boolean Whether to use the luarocks loader to support multiple dependencies (Default: `true`)
---@field reinstall_dev_rocks_on_update? boolean Whether to reinstall 'dev' rocks on update (Default: `true`, as rocks.nvim cannot determine if 'dev' rocks are up to date).
---@field enable_luarocks_loader? boolean Whether to use the luarocks loader to support multiple dependencies (Default: `true`)
---@field luarocks_config? string Path to the luarocks config. If not set, rocks.nvim will create one in `rocks_path`. Warning: You should include the settings in the default luarocks-config.lua before overriding this.

---@type RocksOpts | fun():RocksOpts
vim.g.rocks_nvim = vim.g.rocks_nvim
Expand Down
33 changes: 22 additions & 11 deletions lua/rocks/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
--
-- Copyright (C) 2023 Neorocks Org.
--
-- Version: 0.1.0
-- License: GPLv3
-- Created: 05 Jul 2023
-- Updated: 27 Aug 2023
-- Updated: 15 May 2024
-- Homepage: https://github.com/nvim-neorocks/rocks.nvim
-- Maintainers: NTBBloodbath <bloodbathalchemist@protonmail.com>, Vhyrro <vhyrro@gmail.com>, mrcjkb <marc@jakobi.dev>
--
Expand Down Expand Up @@ -103,23 +102,35 @@ if #config.debug_info.unrecognized_configs > 0 then
)
end

local luarocks_config_path = vim.fs.joinpath(config.rocks_path, "luarocks-config.lua")
fs.write_file(
luarocks_config_path,
"w+",
([==[
lua_version = 5.1
if opts.luarocks_config then
-- luarocks_config override
if vim.uv.fs_stat(opts.luarocks_config) then
---@diagnostic disable-next-line: inject-field
config.luarocks_config = ("%s"):format(opts.luarocks_config)
else
vim.notify("rocks.nvim: luarocks_config does not exist!", vim.log.levels.ERROR)
opts.luarocks_config = nil
end
end
if not opts.luarocks_config then
local luarocks_config_path = vim.fs.joinpath(config.rocks_path, "luarocks-config.lua")
fs.write_file(
luarocks_config_path,
"w+",
([==[
lua_version = "5.1"
rocks_trees = {
{
name = "rocks.nvim",
root = "%s",
},
}
]==]):format(config.rocks_path)
)
)

---@diagnostic disable-next-line: inject-field
config.luarocks_config = ('"%s"'):format(luarocks_config_path)
---@diagnostic disable-next-line: inject-field
config.luarocks_config = ("%s"):format(luarocks_config_path)
end

return config

Expand Down
Loading