refactor(templates): Prioritize copying system templates to ensure latest version

- Refactor template copying order
This commit is contained in:
doodleEsc
2025-07-16 14:28:36 +08:00
committed by yetone
parent 966eef743b
commit 1455ed6005

View File

@@ -245,6 +245,23 @@ function Prompt.get_templates_dir(project_root)
end
end
if Config.rules.project_dir then
local project_rules_path = Path:new(Config.rules.project_dir)
if not project_rules_path:is_absolute() then project_rules_path = directory:joinpath(project_rules_path) end
find_rules(tostring(project_rules_path))
end
find_rules(Config.rules.global_dir)
find_rules(directory:absolute())
local source_dir =
Path:new(debug.getinfo(1).source:match("@?(.*/)"):gsub("/lua/avante/path.lua$", "") .. "templates")
-- Copy built-in templates to cache directory (only if not overridden by user templates)
source_dir:copy({
destination = cache_prompt_dir,
recursive = true,
override = true,
})
-- Check for override prompt
local override_prompt_dir = Config.override_prompt_dir
if override_prompt_dir then
@@ -284,23 +301,6 @@ function Prompt.get_templates_dir(project_root)
end
end
if Config.rules.project_dir then
local project_rules_path = Path:new(Config.rules.project_dir)
if not project_rules_path:is_absolute() then project_rules_path = directory:joinpath(project_rules_path) end
find_rules(tostring(project_rules_path))
end
find_rules(Config.rules.global_dir)
find_rules(directory:absolute())
local source_dir =
Path:new(debug.getinfo(1).source:match("@?(.*/)"):gsub("/lua/avante/path.lua$", "") .. "templates")
-- Copy built-in templates to cache directory (only if not overridden by user templates)
source_dir:copy({
destination = cache_prompt_dir,
recursive = true,
override = true,
})
vim.iter(Prompt.custom_prompts_contents):filter(function(_, v) return v ~= nil end):each(function(k, v)
local orig_file = cache_prompt_dir:joinpath(Prompt.get_builtin_prompts_filepath(k))
local orig_content = orig_file:read()