From 8067cb0240df4c3b360783ab0809b1e0f1bde9f0 Mon Sep 17 00:00:00 2001 From: Christopher Brewin Date: Wed, 18 Dec 2024 21:22:40 +1000 Subject: [PATCH] fix(file_selector): empty buffer and chat without file context. (#953) --- lua/avante/file_selector.lua | 2 ++ lua/avante/llm.lua | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/avante/file_selector.lua b/lua/avante/file_selector.lua index 2493cb6..58c20a1 100644 --- a/lua/avante/file_selector.lua +++ b/lua/avante/file_selector.lua @@ -33,6 +33,8 @@ function FileSelector:reset() end function FileSelector:add_selected_file(filepath) + if not filepath or filepath == "" then return end + local uniform_path = Utils.uniform_path(filepath) -- Avoid duplicates if not vim.tbl_contains(self.selected_filepaths, uniform_path) then diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index a7dbfaf..a08aba4 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -70,8 +70,10 @@ M.generate_prompts = function(opts) if diagnostics ~= "" then table.insert(messages, { role = "user", content = diagnostics }) end end - local code_context = Path.prompts.render_file("_context.avanterules", template_opts) - if code_context ~= "" then table.insert(messages, { role = "user", content = code_context }) end + if #opts.selected_files > 0 or opts.selected_code ~= nil then + local code_context = Path.prompts.render_file("_context.avanterules", template_opts) + if code_context ~= "" then table.insert(messages, { role = "user", content = code_context }) end + end if opts.use_xml_format then table.insert(messages, { role = "user", content = string.format("%s", instructions) })