fix(highlight): allow override (#201)

update envvar parsing from cmdline

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-08-24 20:15:45 -04:00 committed by GitHub
parent a7d3defa3d
commit f99bf767b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 62 additions and 56 deletions

View File

@ -209,6 +209,17 @@ The following key bindings are available for use with `avante.nvim`:
- **Stability Improvements**: Refactor and optimize the codebase to enhance the stability and reliability of the plugin.
- **Expanded Features**: Introduce additional customization options and new features to support a wider range of coding tasks.
## Highlight Groups
| Highlight Group | Description |
|-----------------|-------------|
| AvanteTitle | Title |
| AvanteReversedTitle | Used for rounded border |
| AvanteSubtitle | Selected code title |
| AvanteReversedSubtitle | Used for rounded border |
| AvanteThirdTitle | Prompt title |
| AvanteReversedThirdTitle | Used for rounded border |
## TODOs
- [x] Chat with current file

View File

@ -74,7 +74,9 @@ M.defaults = {
---Specify the behaviour of avante.nvim
---1. auto_apply_diff_after_generation: Whether to automatically apply diff after LLM response.
--- This would simulate similar behaviour to cursor. Default to false.
---2. auto_set_highlight_group: Whether to automatically set the highlight group for the current line. Default to true.
behaviour = {
auto_set_highlight_group = true,
auto_apply_diff_after_generation = false,
},
highlights = {
@ -113,9 +115,6 @@ M.defaults = {
align = "center", -- left, center, right for title
rounded = true,
},
prompt = {
prefix = "> ", -- prefix for the prompt
},
},
--- @class AvanteConflictUserConfig
diff = {

View File

@ -1,13 +1,14 @@
local api = vim.api
local Config = require("avante.config")
local M = {
TITLE = "AvanteTitle",
REVERSED_TITLE = "AvanteReversedTitle",
SUBTITLE = "AvanteSubtitle",
REVERSED_SUBTITLE = "AvanteReversedSubtitle",
THRIDTITLE = "AvanteThirdTitle",
REVERSED_THRIDTITLE = "AvanteReversedThirdTitle",
REVERSED_NORMAL = "AvanteReversedNormal",
THIRD_TITLE = "AvanteThirdTitle",
REVERSED_THIRD_TITLE = "AvanteReversedThirdTitle",
}
M.input_ns = api.nvim_create_namespace("avante_input")
@ -17,13 +18,38 @@ M.setup = function()
local normal = api.nvim_get_hl(0, { name = "Normal" })
local normal_float = api.nvim_get_hl(0, { name = "NormalFloat" })
api.nvim_set_hl(0, M.REVERSED_NORMAL, { fg = normal.bg })
api.nvim_set_hl(0, M.TITLE, { fg = "#1e222a", bg = "#98c379" })
api.nvim_set_hl(0, M.REVERSED_TITLE, { fg = "#98c379" })
api.nvim_set_hl(0, M.SUBTITLE, { fg = "#1e222a", bg = "#56b6c2" })
api.nvim_set_hl(0, M.REVERSED_SUBTITLE, { fg = "#56b6c2" })
api.nvim_set_hl(0, M.THRIDTITLE, { fg = "#ABB2BF", bg = "#353B45" })
api.nvim_set_hl(0, M.REVERSED_THRIDTITLE, { fg = "#353B45" })
local has_set_colors = {}
for _, hl_group in ipairs({
M.TITLE,
M.REVERSED_TITLE,
M.SUBTITLE,
M.REVERSED_SUBTITLE,
M.THIRD_TITLE,
M.REVERSED_THIRD_TITLE,
}) do
has_set_colors[hl_group] = api.nvim_get_hl(0, { name = hl_group }) ~= vim.empty_dict()
end
if Config.behaviour.auto_set_highlight_group then
if not has_set_colors[M.TITLE] then
api.nvim_set_hl(0, M.TITLE, { fg = "#1e222a", bg = "#98c379" })
end
if not has_set_colors[M.REVERSED_TITLE] then
api.nvim_set_hl(0, M.REVERSED_TITLE, { fg = "#98c379" })
end
if not has_set_colors[M.SUBTITLE] then
api.nvim_set_hl(0, M.SUBTITLE, { fg = "#1e222a", bg = "#56b6c2" })
end
if not has_set_colors[M.REVERSED_SUBTITLE] then
api.nvim_set_hl(0, M.REVERSED_SUBTITLE, { fg = "#56b6c2" })
end
if not has_set_colors[M.THIRD_TITLE] then
api.nvim_set_hl(0, M.THIRD_TITLE, { fg = "#ABB2BF", bg = "#353B45" })
end
if not has_set_colors[M.REVERSED_THIRD_TITLE] then
api.nvim_set_hl(0, M.REVERSED_THIRD_TITLE, { fg = "#353B45" })
end
end
api.nvim_set_hl(M.hint_ns, "NormalFloat", { fg = normal_float.fg, bg = normal_float.bg })

View File

@ -96,6 +96,8 @@ M.stream = function(question, code_lang, code_content, selected_content_content,
---@type AvanteCurlOutput
local spec = Provider.parse_curl_args(Provider, code_opts)
Utils.debug({ spec })
---@param line string
local function parse_stream_data(line)
local event = line:match("^event: (.+)$")

View File

@ -107,13 +107,8 @@ E.parse_envvar = function(Opts)
local key = nil
if cmd ~= nil then
local ok, job = pcall(vim.system, vim.split(cmd, " ", { trimempty = true }), { text = true })
if not ok then
Utils.error("Failed to execute command to retrieve secrets: " .. cmd, { once = true, title = "Avante" })
else
local out = job:wait()
key = out.stdout
end
local result = vim.system(vim.split(cmd, " ", { trimempty = true }), { text = true }):wait()
key = vim.split(result.stdout, "\n")[1]
else
key = os.getenv(api_key_name)
end

View File

@ -31,11 +31,11 @@ local Sidebar = {}
---@field augroup integer
---@field code avante.CodeState
---@field winids table<string, integer> this table stores the winids of the sidebar components (result_container, result, selected_code_container, selected_code, input_container, input), even though they are destroyed.
---@field result_container AvanteComp | nil
---@field result_container NuiSplit | nil
---@field result FloatingWindow | nil
---@field selected_code_container AvanteComp | nil
---@field selected_code_container NuiSplit | nil
---@field selected_code FloatingWindow | nil
---@field input_container AvanteComp | nil
---@field input_container NuiSplit | nil
---@field input FloatingWindow | nil
---@param id integer the tabpage id retrieved from api.nvim_get_current_tabpage()
@ -68,7 +68,6 @@ end
function Sidebar:reset()
self:delete_autocmds()
self.registered_cmp = false
self.code = { bufnr = 0, winid = 0, selection = nil }
self.winids = { result_container = 0, result = 0, selected_code = 0, input = 0 }
self.result_container = nil
@ -433,8 +432,8 @@ function Sidebar:render_input_container()
self.input_container.winid,
self.input_container.bufnr,
header_text,
Highlights.THRIDTITLE,
Highlights.REVERSED_THRIDTITLE
Highlights.THIRD_TITLE,
Highlights.REVERSED_THIRD_TITLE
)
end
@ -549,8 +548,8 @@ function Sidebar:on_mount()
local function unbind_jump_keys()
if self.result and self.result.bufnr and api.nvim_buf_is_valid(self.result.bufnr) then
pcall(vim.keymap.del, "n", "]c", { buffer = self.result.bufnr })
pcall(vim.keymap.del, "n", "[c", { buffer = self.result.bufnr })
pcall(vim.keymap.del, "n", Config.mappings.jump.next, { buffer = self.result.bufnr })
pcall(vim.keymap.del, "n", Config.mappings.jump.prev, { buffer = self.result.bufnr })
end
end
@ -620,7 +619,6 @@ function Sidebar:on_mount()
group = self.augroup,
buffer = self.result.bufnr,
callback = function()
self:focus()
if self.input and self.input.winid and api.nvim_win_is_valid(self.input.winid) then
api.nvim_set_current_win(self.input.winid)
end
@ -1392,7 +1390,7 @@ function Sidebar:create_input()
api.nvim_win_set_hl_ns(hint_window, Highlights.hint_ns)
end
show_hint()
self.input:on(event.InsertEnter, show_hint)
self.input:on_unmount(function()
close_hint()

View File

@ -1,26 +0,0 @@
---@meta
---@class AvanteComp
---@field winid integer | nil
---@field bufnr integer | nil
local AvanteComp = {}
---@return nil
function AvanteComp:mount() end
---@return nil
function AvanteComp:unmount() end
---@param event string | string[]
---@param handler string | function
---@param options? table<"'once'" | "'nested'", boolean>
---@return nil
function AvanteComp:on(event, handler, options) end
-- set keymap for this split
---@param mode string check `:h :map-modes`
---@param key string|string[] key for the mapping
---@param handler string | fun(): nil handler for the mapping
---@param opts? table<"'expr'"|"'noremap'"|"'nowait'"|"'remap'"|"'script'"|"'silent'"|"'unique'", boolean>
---@return nil
function AvanteComp:map(mode, key, handler, opts, ___force___) end

View File

@ -4,6 +4,7 @@ local source = {}
---@param sidebar avante.Sidebar
function source.new(sidebar)
---@type cmp.Source
return setmetatable({
sidebar = sidebar,
}, { __index = source })