From 1455ed600579d4e5041adf6fea0babc27b405f82 Mon Sep 17 00:00:00 2001 From: doodleEsc Date: Wed, 16 Jul 2025 14:28:36 +0800 Subject: [PATCH] refactor(templates): Prioritize copying system templates to ensure latest version - Refactor template copying order --- lua/avante/path.lua | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lua/avante/path.lua b/lua/avante/path.lua index 10db0a7..a7b5053 100644 --- a/lua/avante/path.lua +++ b/lua/avante/path.lua @@ -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()