diff --git a/lua/avante/libs/acp_client.lua b/lua/avante/libs/acp_client.lua index 769c4c2..4f13072 100644 --- a/lua/avante/libs/acp_client.lua +++ b/lua/avante/libs/acp_client.lua @@ -532,7 +532,7 @@ function ACPClient:_handle_message(message) self:_handle_notification(message.id, message.method, message.params) elseif message.id and (message.result or message.error) then if self.debug_log_file then - self.debug_log_file:write("response: " .. vim.inspect(message) .. string.rep("=", 100) .. "\n") + self.debug_log_file:write("response: " .. vim.inspect(message) .. "\n" .. string.rep("=", 100) .. "\n") self.debug_log_file:flush() end local callback = self.callbacks[message.id] diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index a102db7..2ff5400 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -1041,6 +1041,25 @@ function M._stream_acp(opts) opts.on_save_acp_session_id(session_id) end local prompt = {} + if opts.selected_filepaths then + for _, filepath in ipairs(opts.selected_filepaths) do + local abs_path = Utils.to_absolute_path(filepath) + local file_name = vim.fn.fnamemodify(abs_path, ":t") + local prompt_item = acp_client:create_resource_link_content("file://" .. abs_path, file_name) + table.insert(prompt, prompt_item) + end + end + if opts.selected_code then + local prompt_item = { + type = "text", + text = string.format( + "\n%s\n%s\n", + opts.selected_code.path, + opts.selected_code.content + ), + } + table.insert(prompt, prompt_item) + end local history_messages = opts.history_messages or {} if opts.acp_session_id then for i = #history_messages, 1, -1 do @@ -1097,35 +1116,6 @@ function M._stream_acp(opts) end end end - if opts.selected_filepaths then - for _, filepath in ipairs(opts.selected_filepaths) do - local lines, error = Utils.read_file_from_buf_or_disk(filepath) - if error ~= nil then - Utils.error("error reading file: " .. error) - else - local abs_path = Utils.to_absolute_path(filepath) - local content = table.concat(lines or {}, "\n") - local filetype = Utils.get_filetype(filepath) - local prompt_item = acp_client:create_resource_content({ - uri = "file://" .. abs_path, - mimeType = "text/x-" .. filetype, - text = content, - }, nil) - table.insert(prompt, prompt_item) - end - end - end - if opts.selected_code then - local prompt_item = { - type = "text", - text = string.format( - "\n%s\n%s\n", - opts.selected_code.path, - opts.selected_code.content - ), - } - table.insert(prompt, prompt_item) - end acp_client:send_prompt(session_id, prompt, function(_, err_) if err_ then opts.on_stop({ reason = "error", error = err_ })