yetone 8e1018fef7
feat: repo map (#496)
* feat: repo map

* chore: remove breakline

* chore: remove spaces

* fix: golang public method

* feat: mentions for editing input
2024-09-23 18:52:26 +08:00

37 lines
895 B
Lua

local LRUCache = require("avante.utils.lru_cache")
---@class avante.utils.file
local M = {}
local api = vim.api
local fn = vim.fn
local _file_content_lru_cache = LRUCache:new(60)
api.nvim_create_autocmd("BufWritePost", {
callback = function()
local filepath = api.nvim_buf_get_name(0)
local keys = _file_content_lru_cache:keys()
if vim.tbl_contains(keys, filepath) then
local content = table.concat(api.nvim_buf_get_lines(0, 0, -1, false), "\n")
_file_content_lru_cache:set(filepath, content)
end
end,
})
function M.read_content(filepath)
local cached_content = _file_content_lru_cache:get(filepath)
if cached_content then return cached_content end
local content = fn.readfile(filepath)
if content then
content = table.concat(content, "\n")
_file_content_lru_cache:set(filepath, content)
return content
end
return nil
end
return M