fix: selected code (#1542)
This commit is contained in:
@@ -2031,13 +2031,13 @@ local function get_timestamp() return os.date("%Y-%m-%d %H:%M:%S") end
|
|||||||
---@param model string
|
---@param model string
|
||||||
---@param request string
|
---@param request string
|
||||||
---@param selected_filepaths string[]
|
---@param selected_filepaths string[]
|
||||||
---@param selected_code {filetype: string, content: string}?
|
---@param selected_code AvanteSelectedCode?
|
||||||
---@return string
|
---@return string
|
||||||
local function render_chat_record_prefix(timestamp, provider, model, request, selected_filepaths, selected_code)
|
local function render_chat_record_prefix(timestamp, provider, model, request, selected_filepaths, selected_code)
|
||||||
provider = provider or "unknown"
|
provider = provider or "unknown"
|
||||||
model = model or "unknown"
|
model = model or "unknown"
|
||||||
local res = "- Datetime: " .. timestamp .. "\n\n" .. "- Model: " .. provider .. "/" .. model
|
local res = "- Datetime: " .. timestamp .. "\n\n" .. "- Model: " .. provider .. "/" .. model
|
||||||
if selected_filepaths ~= nil then
|
if selected_filepaths ~= nil and #selected_filepaths > 0 then
|
||||||
res = res .. "\n\n- Selected files:"
|
res = res .. "\n\n- Selected files:"
|
||||||
for _, path in ipairs(selected_filepaths) do
|
for _, path in ipairs(selected_filepaths) do
|
||||||
res = res .. "\n - " .. path
|
res = res .. "\n - " .. path
|
||||||
@@ -2047,7 +2047,8 @@ local function render_chat_record_prefix(timestamp, provider, model, request, se
|
|||||||
res = res
|
res = res
|
||||||
.. "\n\n- Selected code: "
|
.. "\n\n- Selected code: "
|
||||||
.. "\n\n```"
|
.. "\n\n```"
|
||||||
.. selected_code.filetype
|
.. (selected_code.file_type or "")
|
||||||
|
.. (selected_code.path and ":" .. selected_code.path or "")
|
||||||
.. "\n"
|
.. "\n"
|
||||||
.. selected_code.content
|
.. selected_code.content
|
||||||
.. "\n```"
|
.. "\n```"
|
||||||
@@ -2085,7 +2086,7 @@ function Sidebar:render_history_content(history)
|
|||||||
for idx, entry in ipairs(history.entries) do
|
for idx, entry in ipairs(history.entries) do
|
||||||
if entry.reset_memory then
|
if entry.reset_memory then
|
||||||
content = content .. "***MEMORY RESET***\n\n"
|
content = content .. "***MEMORY RESET***\n\n"
|
||||||
if idx < #history then content = content .. "-------\n\n" end
|
if idx < #history.entries then content = content .. "-------\n\n" end
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
local selected_filepaths = entry.selected_filepaths
|
local selected_filepaths = entry.selected_filepaths
|
||||||
@@ -2102,7 +2103,7 @@ function Sidebar:render_history_content(history)
|
|||||||
)
|
)
|
||||||
content = content .. prefix
|
content = content .. prefix
|
||||||
content = content .. entry.response .. "\n\n"
|
content = content .. entry.response .. "\n\n"
|
||||||
if idx < #history then content = content .. "-------\n\n" end
|
if idx < #history.entries then content = content .. "-------\n\n" end
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
return content
|
return content
|
||||||
@@ -2432,14 +2433,14 @@ function Sidebar:create_input_container(opts)
|
|||||||
|
|
||||||
local timestamp = get_timestamp()
|
local timestamp = get_timestamp()
|
||||||
|
|
||||||
local filetype = api.nvim_get_option_value("filetype", { buf = self.code.bufnr })
|
|
||||||
|
|
||||||
local selected_filepaths = self.file_selector:get_selected_filepaths()
|
local selected_filepaths = self.file_selector:get_selected_filepaths()
|
||||||
|
|
||||||
|
---@type AvanteSelectedCode | nil
|
||||||
local selected_code = nil
|
local selected_code = nil
|
||||||
if self.code.selection ~= nil then
|
if self.code.selection ~= nil then
|
||||||
selected_code = {
|
selected_code = {
|
||||||
filetype = filetype,
|
path = self.code.selection.filepath,
|
||||||
|
file_type = self.code.selection.filetype,
|
||||||
content = self.code.selection.content,
|
content = self.code.selection.content,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ vim.g.avante_login = vim.g.avante_login
|
|||||||
---@field response string
|
---@field response string
|
||||||
---@field original_response string
|
---@field original_response string
|
||||||
---@field selected_file {filepath: string}?
|
---@field selected_file {filepath: string}?
|
||||||
---@field selected_code {filetype: string, content: string}?
|
---@field selected_code AvanteSelectedCode | nil
|
||||||
---@field reset_memory boolean?
|
---@field reset_memory boolean?
|
||||||
---@field selected_filepaths string[] | nil
|
---@field selected_filepaths string[] | nil
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -31,13 +31,17 @@ function M.entries_to_llm_messages(entries)
|
|||||||
local messages = {}
|
local messages = {}
|
||||||
for _, entry in ipairs(entries) do
|
for _, entry in ipairs(entries) do
|
||||||
local user_content = ""
|
local user_content = ""
|
||||||
if entry.selected_file ~= nil then
|
if entry.selected_filepaths ~= nil then
|
||||||
user_content = user_content .. "SELECTED FILE: " .. entry.selected_file.filepath .. "\n\n"
|
user_content = user_content .. "SELECTED FILES:\n\n"
|
||||||
|
for _, filepath in ipairs(entry.selected_filepaths) do
|
||||||
|
user_content = user_content .. filepath .. "\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if entry.selected_code ~= nil then
|
if entry.selected_code ~= nil then
|
||||||
user_content = user_content
|
user_content = user_content
|
||||||
.. "SELECTED CODE:\n\n```"
|
.. "SELECTED CODE:\n\n```"
|
||||||
.. entry.selected_code.filetype
|
.. (entry.selected_code.file_type or "")
|
||||||
|
.. (entry.selected_code.path and ":" .. entry.selected_code.path or "")
|
||||||
.. "\n"
|
.. "\n"
|
||||||
.. entry.selected_code.content
|
.. entry.selected_code.content
|
||||||
.. "\n```\n\n"
|
.. "\n```\n\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user