fix(highlight): respect user bold configuration (fixes #448) (#450)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-09-01 19:33:04 -04:00 committed by GitHub
parent c33ab80d88
commit 96d060db83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 21 deletions

View File

@ -135,7 +135,7 @@ M.defaults = {
}, },
}, },
windows = { windows = {
---@type "right" | "left" | "top" | "bottom" ---@alias AvantePosition "right" | "left" | "top" | "bottom"
position = "right", position = "right",
wrap = true, -- similar to vim.o.wrap wrap = true, -- similar to vim.o.wrap
width = 30, -- default % based on available width in vertical layout width = 30, -- default % based on available width in vertical layout
@ -171,12 +171,10 @@ M.options = {}
---@field highlights AvanteConflictHighlights ---@field highlights AvanteConflictHighlights
M.diff = {} M.diff = {}
---@class AvanteHintsConfig
---@field enabled boolean
M.hints = {}
---@param opts? avante.Config ---@param opts? avante.Config
function M.setup(opts) function M.setup(opts)
vim.validate({ opts = { opts, "table", true } })
M.options = vim.tbl_deep_extend( M.options = vim.tbl_deep_extend(
"force", "force",
M.defaults, M.defaults,
@ -184,7 +182,7 @@ function M.setup(opts)
---@type avante.Config ---@type avante.Config
{ {
behaviour = { behaviour = {
support_paste_from_clipboard = M.support_paste_image(), support_paste_from_clipboard = M.support_paste_image(true),
}, },
} }
) )
@ -193,25 +191,28 @@ function M.setup(opts)
M.options.silent_warning = not M.options.debug M.options.silent_warning = not M.options.debug
end end
vim.validate({ provider = { M.options.provider, "string", false } })
M.diff = vim.tbl_deep_extend( M.diff = vim.tbl_deep_extend(
"force", "force",
{}, {},
M.options.diff, M.options.diff,
{ mappings = M.options.mappings.diff, highlights = M.options.highlights.diff } { mappings = M.options.mappings.diff, highlights = M.options.highlights.diff }
) )
M.hints = vim.tbl_deep_extend("force", {}, M.options.hints)
if next(M.options.vendors) ~= nil then if next(M.options.vendors) ~= nil then
for k, v in pairs(M.options.vendors) do for k, v in pairs(M.options.vendors) do
M.options.vendors[k] = type(v) == "function" and v() or v M.options.vendors[k] = type(v) == "function" and v() or v
end end
vim.validate({ vendors = { M.options.vendors, "table", true } })
end end
end end
---@param opts? avante.Config ---@param opts? avante.Config
function M.override(opts) function M.override(opts)
opts = opts or {} vim.validate({ opts = { opts, "table", true } })
M.options = vim.tbl_deep_extend("force", M.options, opts)
M.options = vim.tbl_deep_extend("force", M.options, opts or {})
if not M.options.silent_warning then if not M.options.silent_warning then
-- set silent_warning to true if debug is false -- set silent_warning to true if debug is false
M.options.silent_warning = not M.options.debug M.options.silent_warning = not M.options.debug
@ -223,12 +224,12 @@ function M.override(opts)
M.options.diff, M.options.diff,
{ mappings = M.options.mappings.diff, highlights = M.options.highlights.diff } { mappings = M.options.mappings.diff, highlights = M.options.highlights.diff }
) )
M.hints = vim.tbl_deep_extend("force", {}, M.options.hints)
if next(M.options.vendors) ~= nil then if next(M.options.vendors) ~= nil then
for k, v in pairs(M.options.vendors) do for k, v in pairs(M.options.vendors) do
M.options.vendors[k] = type(v) == "function" and v() or v M.options.vendors[k] = type(v) == "function" and v() or v
end end
vim.validate({ vendors = { M.options.vendors, "table", true } })
end end
end end

View File

@ -14,11 +14,11 @@ local Highlights = {
} }
Highlights.conflict = { Highlights.conflict = {
CURRENT = { name = "AvanteConflictCurrent", bg = 4218238 }, -- #405d7e CURRENT = { name = "AvanteConflictCurrent", bg = 4218238, bold = true }, -- #405d7e
CURRENT_LABEL = { name = "AvanteConflictCurrentLabel", link = "CURRENT", shade = 60 }, CURRENT_LABEL = { name = "AvanteConflictCurrentLabel", link = "CURRENT", shade = 60 },
INCOMING = { name = "AvanteConflictIncoming", bg = 3229523 }, -- #314753 INCOMING = { name = "AvanteConflictIncoming", bg = 3229523, bold = true }, -- #314753
INCOMING_LABEL = { name = "AvanteConflictIncomingLabel", link = "INCOMING", shade = 60 }, INCOMING_LABEL = { name = "AvanteConflictIncomingLabel", link = "INCOMING", shade = 60 },
ANCESTOR = { name = "AvanteConflictAncestor", bg = 6824314 }, -- #68217A ANCESTOR = { name = "AvanteConflictAncestor", bg = 6824314, bold = true }, -- #68217A
ANCESTOR_LABEL = { name = "AvanteConflictAncestorLabel", link = "ANCESTOR", shade = 60 }, ANCESTOR_LABEL = { name = "AvanteConflictAncestorLabel", link = "ANCESTOR", shade = 60 },
} }
@ -64,15 +64,14 @@ end
M.conflict_highlights = function(opts) M.conflict_highlights = function(opts)
opts = opts or Config.diff.highlights opts = opts or Config.diff.highlights
local get_highlights = function(key, hl)
local cl = api.nvim_get_hl(0, { name = opts[key:lower()] })
return cl ~= nil and cl or api.nvim_get_hl(0, { name = hl.name })
end
local get_default_colors = function(key, hl) local get_default_colors = function(key, hl)
--- We will first check for user custom highlight. Then fallback to default name highlight. --- We will first check for user custom highlight. Then fallback to default name highlight.
local cl return get_highlights(key, hl).bg or hl.bg
cl = api.nvim_get_hl(0, { name = opts[key:lower()] })
if cl ~= nil then
return cl.bg or hl.bg
end
cl = api.nvim_get_hl(0, { name = hl.name })
return cl.bg or hl.bg
end end
local get_shade = function(hl) local get_shade = function(hl)
@ -85,7 +84,11 @@ M.conflict_highlights = function(opts)
if hl.link ~= nil then if hl.link ~= nil then
api.nvim_set_hl(0, hl.name, { bg = get_shade(hl), default = true }) api.nvim_set_hl(0, hl.name, { bg = get_shade(hl), default = true })
else else
api.nvim_set_hl(0, hl.name, { bg = get_default_colors(key, hl), default = true, bold = true }) api.nvim_set_hl(
0,
hl.name,
{ bg = get_default_colors(key, hl), default = true, bold = get_highlights(key, hl).bold or hl.bold }
)
end end
end end
end) end)