diff --git a/lua/avante/diff.lua b/lua/avante/diff.lua index f7e800e..485b851 100644 --- a/lua/avante/diff.lua +++ b/lua/avante/diff.lua @@ -90,7 +90,7 @@ local ANCESTOR_LABEL_HL = "AvanteConflictAncestorLabel" local PRIORITY = vim.highlight.priorities.user local NAMESPACE = api.nvim_create_namespace("avante-conflict") local KEYBINDING_NAMESPACE = api.nvim_create_namespace("avante-conflict-keybinding") -local AUGROUP_NAME = "AvanteConflictCommands" +local AUGROUP_NAME = "avante_conflicts" local conflict_start = "^<<<<<<<" local conflict_middle = "^=======" diff --git a/lua/avante/init.lua b/lua/avante/init.lua index b236d0b..24ba944 100644 --- a/lua/avante/init.lua +++ b/lua/avante/init.lua @@ -64,7 +64,7 @@ H.keymaps = function() }) end -H.augroup = api.nvim_create_augroup("avante-autocmds", { clear = true }) +H.augroup = api.nvim_create_augroup("avante_autocmds", { clear = true }) H.autocmds = function() local ok, LazyConfig = pcall(require, "lazy.core.config") diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index 476a9f4..d230a15 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -63,7 +63,7 @@ Replace lines: {{start_line}}-{{end_line}} Remember: Accurate line numbers are CRITICAL. The range start_line to end_line must include ALL lines to be replaced, from the very first to the very last. Double-check every range before finalizing your response, paying special attention to the start_line to ensure it hasn't shifted down. Ensure that your line numbers perfectly match the original code structure without any overall shift. ]] -local group = api.nvim_create_augroup("AvanteLLM", { clear = true }) +local group = api.nvim_create_augroup("avante_llm", { clear = true }) local active_job = nil ---@param question string diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index deb2638..8c9f2cf 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -544,6 +544,7 @@ function Sidebar:on_mount() if target_block then api.nvim_win_set_cursor(self.result.winid, { target_block.start_line + 1, 0 }) + vim.cmd("normal! zz") end end diff --git a/lua/avante/tiktoken.lua b/lua/avante/tiktoken.lua index bb2377a..55a13b6 100644 --- a/lua/avante/tiktoken.lua +++ b/lua/avante/tiktoken.lua @@ -21,6 +21,8 @@ local function file_exists(name) end --- Load tiktoken data from cache or download it +---@param model string +---@param done fun(path: string): nil local function load_tiktoken_data(done, model) local tiktoken_url = "https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken" -- If model is gpt-4o, use o200k_base.tiktoken @@ -28,7 +30,8 @@ local function load_tiktoken_data(done, model) tiktoken_url = "https://openaipublic.blob.core.windows.net/encodings/o200k_base.tiktoken" end local async - async = vim.loop.new_async(function() + ---@cast async uv_async_t + async = vim.uv.new_async(function() -- Take filename after the last slash of the url local cache_path = get_cache_path(tiktoken_url:match(".+/(.+)")) if not file_exists(cache_path) then @@ -73,6 +76,8 @@ function M.available() return tiktoken_core ~= nil end +---@param prompt string +---@return integer[] | nil function M.encode(prompt) if not tiktoken_core then return nil @@ -87,6 +92,8 @@ function M.encode(prompt) return tiktoken_core.encode(prompt) end +---@param prompt string +---@return integer function M.count(prompt) if not tiktoken_core then return math.ceil(#prompt * 0.2) -- Fallback to 0.2 character count diff --git a/lua/avante/types.lua b/lua/avante/types.lua index 463404d..bec0604 100644 --- a/lua/avante/types.lua +++ b/lua/avante/types.lua @@ -1,26 +1,18 @@ ---@meta ----@class AvanteComp ----@field winid integer | nil ----@field bufnr integer | nil -local AvanteComp = {} +---@class vim.api.create_autocmd.callback.args +---@field id number +---@field event string +---@field group number? +---@field match string +---@field buf number +---@field file string +---@field data any ----@return nil -function AvanteComp:mount() end +---@class vim.api.keyset.create_autocmd.opts: vim.api.keyset.create_autocmd +---@field callback? fun(ev:vim.api.create_autocmd.callback.args):boolean? ----@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 +--- @param event string | string[] (string|array) Event(s) that will trigger the handler +--- @param opts vim.api.keyset.create_autocmd.opts +--- @return integer +function vim.api.nvim_create_autocmd(event, opts) end diff --git a/lua/avante/utils/tokens.lua b/lua/avante/utils/tokens.lua index 80c19b3..0c6ac11 100644 --- a/lua/avante/utils/tokens.lua +++ b/lua/avante/utils/tokens.lua @@ -2,18 +2,14 @@ local Tiktoken = require("avante.tiktoken") local Tokens = {} ---[[ - cost_per_token - @param {string} token_name - @return {number} cost_per_token -]] +---@type table<[string], number> local cost_per_token = { davinci = 0.000002, } --- Calculate the number of tokens in a given text. --- @param text The text to calculate the number of tokens for. --- @return The number of tokens in the given text. +---@param text string The text to calculate the number of tokens for. +---@return integer The number of tokens in the given text. function Tokens.calculate_tokens(text) if Tiktoken.available() then return Tiktoken.count(text) diff --git a/lua/tiktoken_lib.lua b/lua/tiktoken_lib.lua index 4871e8a..a761651 100644 --- a/lua/tiktoken_lib.lua +++ b/lua/tiktoken_lib.lua @@ -2,7 +2,7 @@ local H = {} local M = {} H.get_os_name = function() - local os_name = vim.loop.os_uname().sysname + local os_name = vim.uv.os_uname().sysname if os_name == "Linux" then return "linux" elseif os_name == "Darwin" then