feat: carry recently viewed files as context (#1538)
This commit is contained in:
@@ -118,6 +118,7 @@ function M.generate_prompts(opts)
|
|||||||
code_lang = opts.code_lang,
|
code_lang = opts.code_lang,
|
||||||
selected_files = opts.selected_files,
|
selected_files = opts.selected_files,
|
||||||
selected_code = opts.selected_code,
|
selected_code = opts.selected_code,
|
||||||
|
recently_viewed_files = opts.recently_viewed_files,
|
||||||
project_context = opts.project_context,
|
project_context = opts.project_context,
|
||||||
diagnostics = opts.diagnostics,
|
diagnostics = opts.diagnostics,
|
||||||
system_info = system_info,
|
system_info = system_info,
|
||||||
|
|||||||
@@ -2400,6 +2400,7 @@ function Sidebar:create_input_container(opts)
|
|||||||
ask = opts.ask or true,
|
ask = opts.ask or true,
|
||||||
project_context = vim.json.encode(project_context),
|
project_context = vim.json.encode(project_context),
|
||||||
selected_files = selected_files_contents,
|
selected_files = selected_files_contents,
|
||||||
|
recently_viewed_files = Utils.get_recent_filepaths(),
|
||||||
diagnostics = vim.json.encode(diagnostics),
|
diagnostics = vim.json.encode(diagnostics),
|
||||||
history_messages = history_messages,
|
history_messages = history_messages,
|
||||||
code_lang = filetype,
|
code_lang = filetype,
|
||||||
|
|||||||
@@ -23,3 +23,11 @@
|
|||||||
</content>
|
</content>
|
||||||
</selected_code>
|
</selected_code>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
{% if recently_viewed_files -%}
|
||||||
|
<recently_viewed_files>
|
||||||
|
{%- for file in recently_viewed_files %}
|
||||||
|
{{loop.index}}. {{file}}
|
||||||
|
{%- endfor %}
|
||||||
|
</recently_viewed_files>
|
||||||
|
{%- endif %}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Tools Usage Guide:
|
|||||||
- Please DON'T be so aggressive in using tools, as many tasks can be better completed without tools.
|
- Please DON'T be so aggressive in using tools, as many tasks can be better completed without tools.
|
||||||
- Files will be provided to you as context through <selected_files> tag!
|
- Files will be provided to you as context through <selected_files> tag!
|
||||||
- Before using the `read_file` tool each time, always repeatedly check whether the file is already in the <selected_files> tag. If it is already there, do not use the `read_file` tool, just read the file content directly from the <selected_files> tag.
|
- Before using the `read_file` tool each time, always repeatedly check whether the file is already in the <selected_files> tag. If it is already there, do not use the `read_file` tool, just read the file content directly from the <selected_files> tag.
|
||||||
|
- If you use the `read_file` tool when file content is already provided in the <selected_files> tag, you will be fired!
|
||||||
- If the `rag_search` tool exists, prioritize using it to do the search!
|
- If the `rag_search` tool exists, prioritize using it to do the search!
|
||||||
- If the `rag_search` tool exists, only use tools like `search_keyword` `search_files` `read_file` `list_files` etc when absolutely necessary!
|
- If the `rag_search` tool exists, only use tools like `search_keyword` `search_files` `read_file` `list_files` etc when absolutely necessary!
|
||||||
- Keep the `query` parameter of `rag_search` tool as concise as possible! Try to keep it within five English words!
|
- Keep the `query` parameter of `rag_search` tool as concise as possible! Try to keep it within five English words!
|
||||||
|
|||||||
@@ -298,6 +298,7 @@ vim.g.avante_login = vim.g.avante_login
|
|||||||
---@class AvanteTemplateOptions
|
---@class AvanteTemplateOptions
|
||||||
---@field ask boolean
|
---@field ask boolean
|
||||||
---@field code_lang string
|
---@field code_lang string
|
||||||
|
---@field recently_viewed_files string[] | nil
|
||||||
---@field selected_code AvanteSelectedCode | nil
|
---@field selected_code AvanteSelectedCode | nil
|
||||||
---@field project_context string | nil
|
---@field project_context string | nil
|
||||||
---@field selected_files AvanteSelectedFile[] | nil
|
---@field selected_files AvanteSelectedFile[] | nil
|
||||||
|
|||||||
@@ -642,15 +642,21 @@ end
|
|||||||
-- Get recent filepaths in the same project and same file ext
|
-- Get recent filepaths in the same project and same file ext
|
||||||
---@param limit? integer
|
---@param limit? integer
|
||||||
---@param filenames? string[]
|
---@param filenames? string[]
|
||||||
|
---@param same_file_ext? boolean
|
||||||
---@return string[]
|
---@return string[]
|
||||||
function M.get_recent_filepaths(limit, filenames)
|
function M.get_recent_filepaths(limit, filenames, same_file_ext)
|
||||||
local project_root = M.get_project_root()
|
local project_root = M.get_project_root()
|
||||||
local current_ext = fn.expand("%:e")
|
local current_ext = fn.expand("%:e")
|
||||||
local oldfiles = vim.v.oldfiles
|
local oldfiles = vim.v.oldfiles
|
||||||
local recent_files = {}
|
local recent_files = {}
|
||||||
|
|
||||||
for _, file in ipairs(oldfiles) do
|
for _, file in ipairs(oldfiles) do
|
||||||
if vim.startswith(file, project_root) and M.is_same_file_ext(current_ext, file) then
|
if vim.startswith(file, project_root) then
|
||||||
|
local has_ext = file:match("%.%w+$")
|
||||||
|
if not has_ext then goto continue end
|
||||||
|
if same_file_ext then
|
||||||
|
if not M.is_same_file_ext(current_ext, file) then goto continue end
|
||||||
|
end
|
||||||
if filenames and #filenames > 0 then
|
if filenames and #filenames > 0 then
|
||||||
for _, filename in ipairs(filenames) do
|
for _, filename in ipairs(filenames) do
|
||||||
if file:find(filename) then table.insert(recent_files, file) end
|
if file:find(filename) then table.insert(recent_files, file) end
|
||||||
@@ -660,6 +666,7 @@ function M.get_recent_filepaths(limit, filenames)
|
|||||||
end
|
end
|
||||||
if #recent_files >= (limit or 10) then break end
|
if #recent_files >= (limit or 10) then break end
|
||||||
end
|
end
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
|
|
||||||
return recent_files
|
return recent_files
|
||||||
|
|||||||
Reference in New Issue
Block a user