From cf230f4bc8c768b12ac04045cad1479cbdb31990 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 24 Mar 2025 16:51:09 +0800 Subject: [PATCH] fix: setup highlights (#1694) --- lua/avante/highlights.lua | 17 ++++++++++++++--- lua/avante/init.lua | 11 +++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lua/avante/highlights.lua b/lua/avante/highlights.lua index 56bed8f..d0ce1fd 100644 --- a/lua/avante/highlights.lua +++ b/lua/avante/highlights.lua @@ -57,6 +57,9 @@ local function has_set_colors(hl_group) return next(hl) ~= nil end +local first_setup = true +local already_set_highlights = {} + function M.setup() if Config.behaviour.auto_set_highlight_group then vim @@ -66,7 +69,8 @@ function M.setup() return k:match("^%u+_") or k:match("^%u+$") end) :each(function(_, hl) - if not has_set_colors(hl.name) then + if first_setup and has_set_colors(hl.name) then already_set_highlights[hl.name] = true end + if not already_set_highlights[hl.name] then local bg = hl.bg local fg = hl.fg if hl.bg_link ~= nil then bg = api.nvim_get_hl(0, { name = hl.bg_link, link = false }).bg end @@ -82,6 +86,13 @@ function M.setup() end) end + if first_setup then + vim.iter(Highlights.conflict):each(function(_, hl) + if hl.name and has_set_colors(hl.name) then already_set_highlights[hl.name] = true end + end) + end + first_setup = false + M.setup_conflict_highlights() end @@ -103,7 +114,7 @@ function M.setup_conflict_highlights() --- set none shade linked highlights first if hl.shade_link ~= nil and hl.shade ~= nil then return end - if has_set_colors(hl.name) then return end + if already_set_highlights[hl.name] then return end local bg = hl.bg local bold = hl.bold @@ -121,7 +132,7 @@ function M.setup_conflict_highlights() --- only set shade linked highlights if hl.shade_link == nil or hl.shade == nil then return end - if has_set_colors(hl.name) then return end + if already_set_highlights[hl.name] then return end local bg local bold = hl.bold diff --git a/lua/avante/init.lua b/lua/avante/init.lua index a9ff786..c8783e0 100644 --- a/lua/avante/init.lua +++ b/lua/avante/init.lua @@ -244,19 +244,22 @@ function H.autocmds() end) local function setup_colors() + Utils.debug("Setting up avante colors") require("avante.highlights").setup() - -- local sidebar = require("avante").get() - -- if sidebar then sidebar:setup_colors() end end api.nvim_create_autocmd("ColorSchemePre", { group = H.augroup, - callback = setup_colors, + callback = function() + vim.schedule(function() setup_colors() end) + end, }) api.nvim_create_autocmd("ColorScheme", { group = H.augroup, - callback = setup_colors, + callback = function() + vim.schedule(function() setup_colors() end) + end, }) -- automatically setup Avante filetype to markdown