Skip to content

Commit

Permalink
add AvantePopupHint and AvanteInlineHint hl groups
Browse files Browse the repository at this point in the history
  • Loading branch information
qdbp committed Sep 15, 2024
1 parent cea3dfb commit f3a8528
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ The following key bindings are available for use with `avante.nvim`:
| AvanteConflictIncoming | Incoming conflict highlight | Default to `Config.highlights.diff.incoming` |
| AvanteConflictCurrentLabel | Current conflict label highlight | Default to shade of `AvanteConflictCurrent` |
| AvanteConflictIncomingLabel | Incoming conflict label highlight | Default to shade of `AvanteConflictIncoming` |
| AvantePopupHint | Usage hints in popup menus | |
| AvanteInlineHint | The end-of-line hint displayed in visual mode | |
See [highlights.lua](./lua/avante/highlights.lua) for more information
Expand Down
10 changes: 2 additions & 8 deletions lua/avante/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ local Highlights = {
REVERSED_THIRD_TITLE = { name = "AvanteReversedThirdTitle", fg = "#353B45" },
SUGGESTION = { name = "AvanteSuggestion", link = "Comment" },
ANNOTATION = { name = "AvanteAnnotation", link = "Comment" },
POPUP_HINT = { name = "AvantePopupHint", link = "NormalFloat" },
INLINE_HINT = { name = "AvanteInlineHint", link = "Keyword" },
}

Highlights.conflict = {
Expand All @@ -29,17 +31,12 @@ local H = {}

local M = {}

M.input_ns = api.nvim_create_namespace("avante_input")
M.hint_ns = api.nvim_create_namespace("avante_hint")

local function has_set_colors(hl_group)
local hl = api.nvim_get_hl(0, { name = hl_group })
return next(hl) ~= nil
end

M.setup = function()
local normal = api.nvim_get_hl(0, { name = "Normal" })
local normal_float = api.nvim_get_hl(0, { name = "NormalFloat" })

if Config.behaviour.auto_set_highlight_group then
vim
Expand All @@ -55,9 +52,6 @@ M.setup = function()
end)
end

api.nvim_set_hl(M.hint_ns, "NormalFloat", { fg = normal_float.fg, bg = normal_float.bg })
api.nvim_set_hl(M.input_ns, "NormalFloat", { fg = normal_float.fg, bg = normal_float.bg })
api.nvim_set_hl(M.input_ns, "FloatBorder", { fg = normal.fg, bg = normal.bg })
M.conflict_highlights()
end

Expand Down
5 changes: 2 additions & 3 deletions lua/avante/selection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Selection:show_shortcuts_hints_popup()
local virt_text_line = self:get_virt_text_line()

self.shortcuts_extmark_id = api.nvim_buf_set_extmark(0, NAMESPACE, virt_text_line, -1, {
virt_text = { { hint_text, "Keyword" } },
virt_text = { { hint_text, "AvanteInlineHint" } },
virt_text_pos = "eol",
priority = PRIORITY,
})
Expand Down Expand Up @@ -175,6 +175,7 @@ function Selection:show_editing_input_shortcuts_hints()

local buf = api.nvim_create_buf(false, true)
api.nvim_buf_set_lines(buf, 0, -1, false, { hint_text })
vim.api.nvim_buf_add_highlight(buf, 0, 'AvantePopupHint', 0, 0, -1)

local function update_spinner()
spinner_index = (spinner_index % #spinner_chars) + 1
Expand Down Expand Up @@ -254,8 +255,6 @@ function Selection:show_editing_input_shortcuts_hints()
}

self.editing_input_shortcuts_hints_winid = api.nvim_open_win(buf, false, opts)

api.nvim_win_set_hl_ns(self.editing_input_shortcuts_hints_winid, Highlights.hint_ns)
end

function Selection:create_editing_input()
Expand Down
5 changes: 1 addition & 4 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ local base_win_options = {
breakindent = true,
wrap = false,
cursorline = false,
-- winhighlight = "Normal:NormalFloat,Border:FloatBorder,VertSplit:NormalFloat,WinSeparator:NormalFloat,CursorLine:NormalFloat",
fillchars = "eob: ",
winhighlight = "CursorLine:Normal,CursorColumn:Normal",
winbar = "",
Expand Down Expand Up @@ -1342,7 +1341,6 @@ function Sidebar:create_input(opts)
end

place_sign_at_first_line(self.input.bufnr)
api.nvim_win_set_hl_ns(self.input.winid, Highlights.input_ns)

if Utils.in_visual_mode() then
-- Exit visual mode
Expand Down Expand Up @@ -1401,6 +1399,7 @@ function Sidebar:create_input(opts)

local buf = api.nvim_create_buf(false, true)
api.nvim_buf_set_lines(buf, 0, -1, false, { hint_text })
vim.api.nvim_buf_add_highlight(buf, 0, 'AvantePopupHint', 0, 0, -1)

-- Get the current window size
local win_width = api.nvim_win_get_width(self.input.winid)
Expand All @@ -1422,8 +1421,6 @@ function Sidebar:create_input(opts)

-- Create the floating window
hint_window = api.nvim_open_win(buf, false, win_opts)

api.nvim_win_set_hl_ns(hint_window, Highlights.hint_ns)
end

api.nvim_create_autocmd({ "TextChanged", "TextChangedI", "VimResized" }, {
Expand Down

0 comments on commit f3a8528

Please sign in to comment.