Skip to content

Commit

Permalink
chore: deprecate g:rocks_nvim.luarocks_config string option
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jul 4, 2024
1 parent 1cb4944 commit 25bbb2b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
34 changes: 16 additions & 18 deletions doc/rocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,29 @@ RocksOpts *RocksOpts*

Fields: ~
{rocks_path?} (string)
Local path in your file system to install rocks
(Default: a `rocks` directory in `vim.fn.stdpath("data")`).
Local path in your file system to install rocks
(Default: a `rocks` directory in `vim.fn.stdpath("data")`).
{config_path?} (string)
Rocks declaration file path (Default: `rocks.toml`) in `vim.fn.stdpath("config")`.
Rocks declaration file path (Default: `rocks.toml`) in `vim.fn.stdpath("config")`.
{luarocks_binary?} (string)
Luarocks binary path (Default: `{rocks_path}/bin/luarocks`).
Luarocks binary path (Default: `{rocks_path}/bin/luarocks`).
{lazy?} (boolean)
Whether to query luarocks.org lazily (Default: `false`).
Setting this to `true` may improve startup time,
but features like auto-completion will lag initially.
Whether to query luarocks.org lazily (Default: `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'.
(Default: `true` for the best default experience).
Whether to automatically add freshly installed plugins to the 'runtimepath'.
(Default: `true` for the best default experience).
{generate_help_pages?} (boolean)
Whether to re-generate plugins help pages after installation/upgrade. (Default: `true`).
Whether to re-generate plugins help pages after installation/upgrade. (Default: `true`).
{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).
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|table)
Path to the luarocks config file or table of extra luarocks config options.
If a table or not set, rocks.nvim will create a default luarocks config in `rocks_path`
and merge it with this table.
Warning: this is a file path, You should include the settings in the default luarocks-config.lua before overriding this.
Whether to use the luarocks loader to support multiple dependencies (Default: `true`).
{luarocks_config?} (table)
Extra luarocks config options.
rocks.nvim will create a default luarocks config in `rocks_path` and merge it with this table (if set).


==============================================================================
Expand Down
8 changes: 3 additions & 5 deletions lua/rocks/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ local config = {}
--- Whether to use the luarocks loader to support multiple dependencies (Default: `true`).
---@field enable_luarocks_loader? boolean
---
--- Path to the luarocks config file or table of extra luarocks config options.
--- If a table or not set, rocks.nvim will create a default luarocks config in `rocks_path`
--- and merge it with this table.
--- Warning: this is a file path, You should include the settings in the default luarocks-config.lua before overriding this.
---@field luarocks_config? string | table
--- Extra luarocks config options.
--- rocks.nvim will create a default luarocks config in `rocks_path` and merge it with this table (if set).
---@field luarocks_config? table

---@type RocksOpts | fun():RocksOpts
vim.g.rocks_nvim = vim.g.rocks_nvim
Expand Down
19 changes: 14 additions & 5 deletions lua/rocks/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ if #config.debug_info.unrecognized_configs > 0 then
end

if type(opts.luarocks_config) == "string" then
vim.deprecate(
"g:rocks_nvim.luarocks_config (string)",
"g:rocks_nvim.luarocks_config (table)",
"3.0.0",
"rocks.nvim"
)
-- luarocks_config override
if vim.uv.fs_stat(opts.luarocks_config) then
local luarocks_config_path = ("%s"):format(opts.luarocks_config)
Expand All @@ -168,11 +174,13 @@ if type(opts.luarocks_config) == "string" then
end
if not opts.luarocks_config or type(opts.luarocks_config) == "table" then
local nio = require("nio")
local semaphore = nio.control.semaphore(1)
local luarocks_config_path
---@diagnostic disable-next-line: inject-field
config.luarocks_config_path = nio.create(function()
semaphore.acquire()
local luarocks_config_path = vim.fs.joinpath(config.rocks_path, "luarocks-config.lua")
if luarocks_config_path then
return luarocks_config_path
end
luarocks_config_path = vim.fs.joinpath(config.rocks_path, "luarocks-config.lua")
local default_luarocks_config = {
lua_version = "5.1",
rocks_trees = {
Expand All @@ -194,8 +202,9 @@ if not opts.luarocks_config or type(opts.luarocks_config) == "table" then

fs.write_file_await(luarocks_config_path, "w+", config_str)

semaphore.release()

vim.schedule(function()
require("rocks.log").debug("Using luarocks config " .. config_str)
end)
---@diagnostic disable-next-line: inject-field
return ("%s"):format(luarocks_config_path)
end)
Expand Down
2 changes: 1 addition & 1 deletion lua/rocks/loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ end

---@type async fun():boolean
loader.enable = nio.create(function()
log.trace("Enabling luarocks loader")
local luarocks_config_path = config.luarocks_config_path()
local luarocks_lua_dir = config.luarocks_binary == config.default_luarocks_binary
and vim.fs.joinpath(config.rocks_path, "share", "lua")
or get_luarocks_lua_dir_from_luarocks()
local future = nio.control.future()
vim.schedule(function()
log.trace("Enabling luarocks loader")
if luarocks_lua_dir then
package.path = package.path
.. ";"
Expand Down
1 change: 0 additions & 1 deletion plugin/rocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ log.trace("loading rocks.adapter")
local adapter = require("rocks.adapter")
log.trace("loading rocks config")
local config = require("rocks.config.internal")
log.debug("Using luarocks config " .. config.luarocks_config)

-- Initialize the luarocks loader
if config.enable_luarocks_loader then
Expand Down

0 comments on commit 25bbb2b

Please sign in to comment.