fix: codeblocks have not been synchronized (#38)
This commit is contained in:
parent
c3c47264f0
commit
dea737bf05
@ -10,6 +10,7 @@ local Diff = require("avante.diff")
|
|||||||
local AiBot = require("avante.ai_bot")
|
local AiBot = require("avante.ai_bot")
|
||||||
local Utils = require("avante.utils")
|
local Utils = require("avante.utils")
|
||||||
|
|
||||||
|
local VIEW_BUFFER_UPDATED_PATTERN = "AvanteViewBufferUpdated"
|
||||||
local CODEBLOCK_KEYBINDING_NAMESPACE = api.nvim_create_namespace("AVANTE_CODEBLOCK_KEYBINDING")
|
local CODEBLOCK_KEYBINDING_NAMESPACE = api.nvim_create_namespace("AVANTE_CODEBLOCK_KEYBINDING")
|
||||||
local PRIORITY = vim.highlight.priorities.user
|
local PRIORITY = vim.highlight.priorities.user
|
||||||
|
|
||||||
@ -196,13 +197,16 @@ end
|
|||||||
|
|
||||||
---@param content string concatenated content of the buffer
|
---@param content string concatenated content of the buffer
|
||||||
---@param focus? boolean whether to focus the result view
|
---@param focus? boolean whether to focus the result view
|
||||||
function Sidebar:update_content(content, focus)
|
function Sidebar:update_content(content, focus, callback)
|
||||||
focus = focus or false
|
focus = focus or false
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
api.nvim_set_option_value("modifiable", true, { buf = self.view.buf })
|
api.nvim_set_option_value("modifiable", true, { buf = self.view.buf })
|
||||||
api.nvim_buf_set_lines(self.view.buf, 0, -1, false, vim.split(content, "\n"))
|
api.nvim_buf_set_lines(self.view.buf, 0, -1, false, vim.split(content, "\n"))
|
||||||
api.nvim_set_option_value("modifiable", false, { buf = self.view.buf })
|
api.nvim_set_option_value("modifiable", false, { buf = self.view.buf })
|
||||||
api.nvim_set_option_value("filetype", "Avante", { buf = self.view.buf })
|
api.nvim_set_option_value("filetype", "Avante", { buf = self.view.buf })
|
||||||
|
if callback ~= nil then
|
||||||
|
callback()
|
||||||
|
end
|
||||||
if focus then
|
if focus then
|
||||||
xpcall(function()
|
xpcall(function()
|
||||||
--- set cursor to bottom of result view
|
--- set cursor to bottom of result view
|
||||||
@ -527,6 +531,13 @@ function Sidebar:render()
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("User", {
|
||||||
|
pattern = VIEW_BUFFER_UPDATED_PATTERN,
|
||||||
|
callback = function()
|
||||||
|
codeblocks = parse_codeblocks(self.view.buf)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
local signal = N.create_signal({ is_loading = false, text = "" })
|
local signal = N.create_signal({ is_loading = false, text = "" })
|
||||||
|
|
||||||
local chat_history = load_chat_history(self)
|
local chat_history = load_chat_history(self)
|
||||||
@ -591,7 +602,10 @@ function Sidebar:render()
|
|||||||
.. "\n\n"
|
.. "\n\n"
|
||||||
.. full_response
|
.. full_response
|
||||||
.. "\n\n**Generation complete!** Please review the code suggestions above.\n\n\n\n",
|
.. "\n\n**Generation complete!** Please review the code suggestions above.\n\n\n\n",
|
||||||
true
|
true,
|
||||||
|
function()
|
||||||
|
api.nvim_exec_autocmds("User", { pattern = VIEW_BUFFER_UPDATED_PATTERN })
|
||||||
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
api.nvim_set_current_win(self.winid.result)
|
api.nvim_set_current_win(self.winid.result)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user