diff --git a/README.md b/README.md index ebf07a4..d167f46 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/avante/config.lua b/lua/avante/config.lua index 51e3cdc..e2951c2 100644 --- a/lua/avante/config.lua +++ b/lua/avante/config.lua @@ -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 = { diff --git a/lua/avante/highlights.lua b/lua/avante/highlights.lua index 1bd2d31..debd933 100644 --- a/lua/avante/highlights.lua +++ b/lua/avante/highlights.lua @@ -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 }) diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index ad6d96f..34f0d35 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -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: (.+)$") diff --git a/lua/avante/providers/init.lua b/lua/avante/providers/init.lua index 2244660..c3a9622 100644 --- a/lua/avante/providers/init.lua +++ b/lua/avante/providers/init.lua @@ -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 diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index add1e86..c64c210 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -31,11 +31,11 @@ local Sidebar = {} ---@field augroup integer ---@field code avante.CodeState ---@field winids table 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() diff --git a/lua/avante/types.lua b/lua/avante/types.lua deleted file mode 100644 index 463404d..0000000 --- a/lua/avante/types.lua +++ /dev/null @@ -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 diff --git a/lua/cmp_avante/commands.lua b/lua/cmp_avante/commands.lua index 5a97949..75ccb5e 100644 --- a/lua/cmp_avante/commands.lua +++ b/lua/cmp_avante/commands.lua @@ -4,6 +4,7 @@ local source = {} ---@param sidebar avante.Sidebar function source.new(sidebar) + ---@type cmp.Source return setmetatable({ sidebar = sidebar, }, { __index = source })