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: option to auto-sync on startup #613

Merged
merged 1 commit into from
Dec 22, 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
3 changes: 3 additions & 0 deletions doc/rocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ 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`).
If unset, rocks.nvim will prompt to sync.
{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
4 changes: 4 additions & 0 deletions lua/rocks/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ 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`).
--- If unset, rocks.nvim will prompt to sync.
---@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 @@ -60,6 +60,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
20 changes: 13 additions & 7 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()
:join(", ")
local prompt = ("rocks.nvim: The following plugins were not found:\n%s.\n\nRun 'Rocks sync'?"):format(
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
Loading