chore: persistent augroup name pattern (#250)

for better augroup management

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham 2024-08-26 22:31:57 -04:00 committed by GitHub
parent f03c0918c9
commit 07af0a91f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 30 additions and 34 deletions

View File

@ -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 = "^======="

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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