From 719a59b783b2eae94c25af9b58459976e499cae1 Mon Sep 17 00:00:00 2001 From: A-Lamia Date: Fri, 14 Jul 2023 17:29:01 +1000 Subject: [PATCH] fix(util): simplify set_highlight and fix settings being cleared This function was doing too much unnecessary things and was resetting user highlights tables to nil as well as unnecessarily trying to merge tables multiple times this changes should also make this function much more performant. --- lua/astrotheme/lib/util.lua | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/lua/astrotheme/lib/util.lua b/lua/astrotheme/lib/util.lua index c349972..ac98fa2 100644 --- a/lua/astrotheme/lib/util.lua +++ b/lua/astrotheme/lib/util.lua @@ -55,25 +55,10 @@ function M.set_palettes(opts) end function M.set_highlights(opts, highlights, theme) - local opts_hl_glob = opts.highlights.global - if opts_hl_glob.modify_hl_groups then - opts_hl_glob.modify_hl_groups(highlights, C) - opts_hl_glob.modify_hl_groups = nil - end - - highlights = vim.tbl_deep_extend("force", highlights, opts_hl_glob) + pcall(opts.highlights.global.modify_hl_groups, highlights, C) + pcall(opts.highlights[theme].modify_hl_groups, highlights, C) - local opts_hl = opts.highlights[theme] - if opts_hl.modify_hl_groups then - opts_hl.modify_hl_groups(highlights, C) - opts_hl.modify_hl_groups = nil - end - - highlights = vim.tbl_deep_extend("force", highlights, opts_hl) for group, spec in pairs(highlights) do - for key, value in pairs(spec) do - if type(value) == table then spec[key] = value:toHex() end - end vim.api.nvim_set_hl(0, group, spec) end end