Skip to content

Commit

Permalink
feat: override auto_setup per plugin via a boolean config field
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored and vhyrro committed Jul 29, 2024
1 parent 9584bd5 commit a8a6862
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ for you.
> it will be invoked with the call to `require`,
> potentially resulting in more eager initialization than necessary.
You can also enable/disable `auto_setup` for individual plugins
by setting `config = true` or `config = false`, respectively.

### Initialization order

rocks.nvim makes use of Neovim's built-in [initialization sequence](https://neovim.io/doc/user/starting.html#initialization),
Expand Down
9 changes: 5 additions & 4 deletions lua/rocks-config/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,20 @@ local function get_config()
return vim.tbl_deep_extend("force", {}, constants.DEFAULT_CONFIG, rocks_toml or {})
end

---@param rock rock_name | RockSpec The rock to configure
---@param rock rock_name | RocksConfigRockSpec The rock to configure
---@param config? RocksConfigConfig
function rocks_config.configure(rock, config)
config = config or get_config()
if type(rock) == "string" then
local all_plugins = api.get_user_rocks()
---@cast all_plugins table<string, RocksConfigRockSpec>
if not all_plugins[rock] then
vim.notify(("[rocks-config.nvim]: Plugin %s not found in rocks.toml"):format(rock), vim.log.levels.ERROR)
return
end
rock = all_plugins[rock]
end
---@cast rock RockSpec
---@cast rock RocksConfigRockSpec
local name = rock.name
if _configured_rocks[name] then
return
Expand All @@ -207,12 +208,12 @@ function rocks_config.configure(rock, config)

-- If there is no custom configuration defined by the user
-- then check for a rock config or attempt to auto-invoke the setup() function.
if not found_custom_configuration and (config.config.auto_setup or rock.config) then
if not found_custom_configuration then
if type(rock.config) == "string" then
xpcall(require, function(err)
table.insert(rocks_config.failed_to_load, { rock.name, rock.config, err })
end, rock.config)
else
elseif rock.config == true or config.config.auto_setup and rock.config ~= false then
auto_setup(plugin_heuristics, config, rock)
end
end
Expand Down
4 changes: 4 additions & 0 deletions lua/rocks-config/meta.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error("Can't require a meta module")

---@class RocksConfigRockSpec: RockSpec
---@field config? string | boolean

0 comments on commit a8a6862

Please sign in to comment.