From 8e4de29933e886a912cc8ef02060fa24d5e83503 Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Mon, 29 Jul 2024 17:19:28 +0200 Subject: [PATCH] fix: rocks-config integration (#9) --- lua/rocks-lazy/internal.lua | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lua/rocks-lazy/internal.lua b/lua/rocks-lazy/internal.lua index 51fe5d9..9caf719 100644 --- a/lua/rocks-lazy/internal.lua +++ b/lua/rocks-lazy/internal.lua @@ -4,18 +4,30 @@ local rocks_lazy = {} function rocks_lazy.load() local api = require("rocks.api") + local log = require("rocks.log") local lz_n = require("lz.n") local user_rocks = api.get_user_rocks() local has_rocks_config, rocks_config = pcall(require, "rocks-config") - ---@param name string - local config_hook = function(name) - if has_rocks_config and type(rocks_config.configure) == "function" then - pcall(vim.cmd.packadd, { name, bang = true }) - rocks_config.configure(name) - end - end + + local config_hook = has_rocks_config + and type(rocks_config.configure) == "function" + ---@param plugin lz.n.Plugin + and function(plugin) + local rock_spec = user_rocks[plugin.name] + if rock_spec then + pcall(vim.cmd.packadd, { plugin.name, bang = true }) + rocks_config.configure(rock_spec) + else + log.warn( + ("rocks-lazy: skipping rocks-config hook because %s not found in user rocks."):format( + plugin.name + ) + ) + end + end + or function(_) end --- HACK: For some reason, if a RockSpec contains a list --- (e.g. colorscheme = [ .. ]) then vim.deepcopy errors