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) })