diff --git a/doc/rocks.txt b/doc/rocks.txt index 12c9fc92..80ffaf85 100644 --- a/doc/rocks.txt +++ b/doc/rocks.txt @@ -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). diff --git a/lua/rocks/config/init.lua b/lua/rocks/config/init.lua index 851782ab..5b334b21 100644 --- a/lua/rocks/config/init.lua +++ b/lua/rocks/config/init.lua @@ -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 diff --git a/lua/rocks/config/internal.lua b/lua/rocks/config/internal.lua index ac70f410..7ab45f69 100644 --- a/lua/rocks/config/internal.lua +++ b/lua/rocks/config/internal.lua @@ -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, diff --git a/lua/rocks/runtime.lua b/lua/rocks/runtime.lua index bd5e8d69..dff34c49 100644 --- a/lua/rocks/runtime.lua +++ b/lua/rocks/runtime.lua @@ -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