Skip to content

Commit

Permalink
feat: option to auto-sync on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Dec 20, 2024
1 parent fb8e5c9 commit 065f392
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions doc/rocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ RocksOpts *RocksOpts*
Whether to re-generate plugins help pages after installation/upgrade. (Default: `true`).
{update_remote_plugins?} (boolean)
Whether to update remote plugins after installation/upgrade. (Default: `true`).
{auto_sync?} (boolean)
Whether to auto-sync if plugins cannot be found on startup. (Default: `false`).
{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).
Expand Down
3 changes: 3 additions & 0 deletions lua/rocks/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ local config = {}
--- Whether to update remote plugins after installation/upgrade. (Default: `true`).
---@field update_remote_plugins? boolean
---
--- Whether to auto-sync if plugins cannot be found on startup. (Default: `false`).
---@field auto_sync? boolean
---
--- Whether to reinstall 'dev' rocks on update
--- (Default: `true`, as rocks.nvim cannot determine if 'dev' rocks are up to date).
---@field reinstall_dev_rocks_on_update? boolean
Expand Down
2 changes: 2 additions & 0 deletions lua/rocks/config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ local default_config = {
update_remote_plugins = true,
---@type boolean Whether to reinstall 'dev' rocks on update
reinstall_dev_rocks_on_update = true,
---@type boolean Whether to auto-sync if plugins cannot be found on startup
auto_sync = false,
---@type boolean Whether to use the luarocks loader to support multiple dependencies
enable_luarocks_loader = true,

Expand Down
18 changes: 12 additions & 6 deletions lua/rocks/runtime.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,26 @@ function runtime.source_start_plugins(user_rocks)
end
end
if #not_found > 0 then
local config = require("rocks.config.internal")
if config.auto_sync then
require("rocks.operations").sync()
return
end
local rock_names = vim
.iter(not_found)
---@param rock_spec RockSpec
:map(function(rock_spec)
return rock_spec.name
end)
:totable()
local prompt = ("rocks.nvim: The following plugins were not found:\n%s.\n\nRun 'Rocks sync'?"):format(
vim.inspect(rock_names)
)
vim.schedule(function()
vim.notify(
("rocks.nvim: You may need to run 'Rocks sync'.\nThe following plugins were not found:\n%s."):format(
vim.inspect(rock_names)
),
vim.log.levels.WARN
)
local choice = vim.fn.confirm(prompt, "&Yes\n&No", 1, "Question")
if choice == 1 then
require("rocks.operations").sync()
end
end)
end
end
Expand Down

0 comments on commit 065f392

Please sign in to comment.