From 43032aac210b04407dddb399982a11d19a9a1ad9 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Wed, 15 May 2024 16:41:04 +0200 Subject: [PATCH] feat: allow overriding luarocks config --- doc/rocks.txt | 17 +++++++++-------- lua/rocks/config/init.lua | 5 +++-- lua/rocks/config/internal.lua | 33 ++++++++++++++++++++++----------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/doc/rocks.txt b/doc/rocks.txt index 5f5527a3..280d2f1e 100644 --- a/doc/rocks.txt +++ b/doc/rocks.txt @@ -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. ============================================================================== diff --git a/lua/rocks/config/init.lua b/lua/rocks/config/init.lua index e63d0b56..87fd10a7 100644 --- a/lua/rocks/config/init.lua +++ b/lua/rocks/config/init.lua @@ -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 diff --git a/lua/rocks/config/internal.lua b/lua/rocks/config/internal.lua index ce547454..6e4eacfc 100644 --- a/lua/rocks/config/internal.lua +++ b/lua/rocks/config/internal.lua @@ -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 , Vhyrro , mrcjkb -- @@ -103,12 +102,23 @@ 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", @@ -116,10 +126,11 @@ rocks_trees = { }, } ]==]):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