Skip to content

Commit

Permalink
fix: codeblocks have not been synchronized (#38)
Browse files Browse the repository at this point in the history
yetone authored Aug 17, 2024
1 parent c3c4726 commit dea737b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ local Diff = require("avante.diff")
local AiBot = require("avante.ai_bot")
local Utils = require("avante.utils")

local VIEW_BUFFER_UPDATED_PATTERN = "AvanteViewBufferUpdated"
local CODEBLOCK_KEYBINDING_NAMESPACE = api.nvim_create_namespace("AVANTE_CODEBLOCK_KEYBINDING")
local PRIORITY = vim.highlight.priorities.user

@@ -196,13 +197,16 @@ end

---@param content string concatenated content of the buffer
---@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
vim.defer_fn(function()
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_set_option_value("modifiable", false, { buf = self.view.buf })
api.nvim_set_option_value("filetype", "Avante", { buf = self.view.buf })
if callback ~= nil then
callback()
end
if focus then
xpcall(function()
--- set cursor to bottom of result view
@@ -527,6 +531,13 @@ function Sidebar:render()
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 chat_history = load_chat_history(self)
@@ -591,7 +602,10 @@ function Sidebar:render()
.. "\n\n"
.. full_response
.. "\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)

0 comments on commit dea737b

Please sign in to comment.