
* feat: autobuild tiktoken lib and schenanigans Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: revert readme changes Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * fix(build): windows Signed-off-by: Hanchin Hsieh <me@yuchanns.xyz> * chore(plugin): early load commands and base setup Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * fix(build): make sync Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * feat: rust go vroom vroom Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * feat: scuffed afaf implementation binding go brrrr Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: remove dups Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * fix(tokens): calculate whether we should do prompt_caching (fixes #416) Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: ignore lockfiles Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * Update README.md * Update crates/avante-tokenizers/README.md * chore: remove unused Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: remove auto build Signed-off-by: Aaron Pham <contact@aarnphm.xyz> --------- Signed-off-by: Aaron Pham <contact@aarnphm.xyz> Signed-off-by: Hanchin Hsieh <me@yuchanns.xyz> Co-authored-by: yuchanns <me@yuchanns.xyz>
63 lines
1.6 KiB
Lua
63 lines
1.6 KiB
Lua
local fn, api = vim.fn, vim.api
|
|
local Path = require("plenary.path")
|
|
local Config = require("avante.config")
|
|
|
|
---@class avante.Path
|
|
---@field history_path Path
|
|
---@field cache_path Path
|
|
local P = {}
|
|
|
|
local M = {}
|
|
|
|
local H = {}
|
|
---@param bufnr integer
|
|
---@return string
|
|
H.filename = function(bufnr)
|
|
local code_buf_name = api.nvim_buf_get_name(bufnr)
|
|
-- Replace path separators with double underscores
|
|
local path_with_separators = fn.substitute(code_buf_name, "/", "__", "g")
|
|
-- Replace other non-alphanumeric characters with single underscores
|
|
return fn.substitute(path_with_separators, "[^A-Za-z0-9._]", "_", "g") .. ".json"
|
|
end
|
|
|
|
---@param bufnr integer
|
|
---@return Path
|
|
M.get = function(bufnr)
|
|
return Path:new(Config.history.storage_path):joinpath(H.filename(bufnr))
|
|
end
|
|
|
|
---@param bufnr integer
|
|
M.load = function(bufnr)
|
|
local history_file = M.get(bufnr)
|
|
if history_file:exists() then
|
|
local content = history_file:read()
|
|
return content ~= nil and vim.json.decode(content) or {}
|
|
end
|
|
return {}
|
|
end
|
|
|
|
---@param bufnr integer
|
|
---@param history table
|
|
M.save = function(bufnr, history)
|
|
local history_file = M.get(bufnr)
|
|
history_file:write(vim.json.encode(history), "w")
|
|
end
|
|
|
|
P.history = M
|
|
|
|
P.setup = function()
|
|
local history_path = Path:new(Config.history.storage_path)
|
|
if not history_path:exists() then
|
|
history_path:mkdir({ parents = true })
|
|
end
|
|
P.history_path = history_path
|
|
|
|
local cache_path = Path:new(vim.fn.stdpath("cache") .. "/avante")
|
|
if not cache_path:exists() then
|
|
cache_path:mkdir({ parents = true })
|
|
end
|
|
P.cache_path = cache_path
|
|
end
|
|
|
|
return P
|