diff --git a/doc/rocks.txt b/doc/rocks.txt index e7e3a0d4..eb268874 100644 --- a/doc/rocks.txt +++ b/doc/rocks.txt @@ -34,9 +34,10 @@ rocks.nvim commands *rocks.commands* The rock must be installed by luarocks. It is added to the 'runtimepath' if it wasn't there yet. If `Rocks` is called with the optional `!`, the rock is added - to the 'runtimepath' and no 'plugin' or 'ftdetect' scripts are + to the |runtimepath| and no |plugin| or |ftdetect| scripts are sourced. - This command aims to behave similarly to the builtin 'packadd'. + This command aims to behave similarly to the builtin |packadd|, + and will fall back to it if no rock is found. To make a rock optional, set `opt = true` in `rocks.toml`. log Open the log file. diff --git a/lua/rocks/commands.lua b/lua/rocks/commands.lua index 3f3cce8e..6a39fa1f 100644 --- a/lua/rocks/commands.lua +++ b/lua/rocks/commands.lua @@ -18,9 +18,10 @@ --- The rock must be installed by luarocks. --- It is added to the 'runtimepath' if it wasn't there yet. --- If `Rocks` is called with the optional `!`, the rock is added ---- to the 'runtimepath' and no 'plugin' or 'ftdetect' scripts are +--- to the |runtimepath| and no |plugin| or |ftdetect| scripts are --- sourced. ---- This command aims to behave similarly to the builtin 'packadd'. +--- This command aims to behave similarly to the builtin |packadd|, +--- and will fall back to it if no rock is found. --- To make a rock optional, set `opt = true` in `rocks.toml`. --- log Open the log file. --- diff --git a/lua/rocks/runtime.lua b/lua/rocks/runtime.lua index 796404a7..a630c11b 100644 --- a/lua/rocks/runtime.lua +++ b/lua/rocks/runtime.lua @@ -111,7 +111,8 @@ end ---@class (exact) PackaddOpts ---@field bang? boolean ----@field error_on_not_found? boolean +---@field packadd_fallback? boolean Fall back to the builtin |packadd|? Default `true`. +---@field error_on_not_found? boolean Notify with an error message if no plugin could be found. Ignored if `packadd_fallback` is set to `true`. ---@param rock_name rock_name ---@param opts? PackaddOpts @@ -120,7 +121,8 @@ function runtime.packadd(rock_name, opts) ---@cast opts table opts = vim.tbl_deep_extend("force", { bang = false, - error_on_not_found = true, + packadd_fallback = true, + error_on_not_found = false, }, opts or {}) local rtp_glob = mk_rtp_glob(rock_name) rtp_append(rtp_glob) @@ -129,7 +131,9 @@ function runtime.packadd(rock_name, opts) end local paths = vim.fn.glob(rtp_glob, nil, true) if #paths == 0 then - if opts.error_on_not_found then + if opts.packadd_fallback then + vim.cmd.packadd({ rock_name, bang = opts.bang }) + elseif opts.error_on_not_found then vim.notify(("No path found for %s"):format(rock_name), vim.log.levels.ERROR) end return