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 27563a6
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: nightly
version: stable
- name: Install rocks.nvim
run: |
mkdir rocks
Expand All @@ -54,7 +54,7 @@ jobs:
cat rocks/rocks.log
echo "vim.cmd.colorscheme('sweetie')" >> .github/resources/init-integration.lua
echo "vim.cmd.e('success')" >> .github/resources/init-integration.lua
nvim -u .github/resources/init-integration.lua -c +wq
nvim -u .github/resources/init-integration.lua -c 'set noswapfile' +wq || true
if [ ! -f success ]; then
echo "Integration test failed!"
exit 1
Expand Down
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
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
inherit nvim;
plugins = with pkgs.lua51Packages; [
toml-edit
toml
fidget-nvim
fzy
nvim-nio
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
21 changes: 15 additions & 6 deletions lua/rocks/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ local default_config = {
vim.tbl_deep_extend("force", vim.empty_dict(), rocks_toml.rocks or {}, rocks_toml.plugins or {})
return config.apply_rock_spec_modifiers(user_rocks)
end,
---@type fun():string
---@type async fun():string
luarocks_config_path = nil,
}

Expand Down 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 nix/test-overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
with ps; [
final.lua51Packages.luarocks-rock
toml-edit
toml
fidget-nvim
fzy
nvim-nio
Expand Down
5 changes: 3 additions & 2 deletions plugin/rocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ 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
nio.run(require("rocks.loader").enable)
nio.run(function()
require("rocks.loader").enable()
end)
end

-- Set up the Rocks user command
Expand Down

0 comments on commit 27563a6

Please sign in to comment.