chore(cmd): add manual refresh and update types (#44)
* chore(cmd): add manual refresh and update types Signed-off-by: Aaron Pham <contact@aarnphm.xyz> * chore: add refresh mapping Signed-off-by: Aaron Pham <contact@aarnphm.xyz> --------- Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
parent
d0d4f8a27c
commit
95b42e835f
@ -34,6 +34,7 @@ M.defaults = {
|
||||
mappings = {
|
||||
ask = "<leader>aa",
|
||||
edit = "<leader>ae",
|
||||
refresh = "<leader>ar",
|
||||
diff = {
|
||||
ours = "co",
|
||||
theirs = "ct",
|
||||
|
@ -34,10 +34,14 @@ H.commands = function()
|
||||
end
|
||||
sidebar:close()
|
||||
end, { desc = "avante: close chat window" })
|
||||
cmd("Refresh", function()
|
||||
M.refresh()
|
||||
end, { desc = "avante: refresh windows" })
|
||||
end
|
||||
|
||||
H.keymaps = function()
|
||||
vim.keymap.set({ "n", "v" }, Config.mappings.ask, M.toggle, { noremap = true })
|
||||
vim.keymap.set("n", Config.mappings.refresh, M.refresh, { noremap = true })
|
||||
end
|
||||
|
||||
H.autocmds = function()
|
||||
@ -123,6 +127,32 @@ M.toggle = function()
|
||||
return sidebar:toggle()
|
||||
end
|
||||
|
||||
M.refresh = function()
|
||||
local sidebar = M._get()
|
||||
if not sidebar then
|
||||
return
|
||||
end
|
||||
local curbuf = vim.api.nvim_get_current_buf()
|
||||
|
||||
local focused = sidebar.view.buf == curbuf or sidebar.bufnr.result == curbuf or sidebar.bufnr.input == curbuf
|
||||
if focused or not sidebar.view:is_open() then
|
||||
return
|
||||
end
|
||||
|
||||
local ft = vim.api.nvim_get_option_value("filetype", { buf = curbuf })
|
||||
local listed = vim.api.nvim_get_option_value("buflisted", { buf = curbuf })
|
||||
|
||||
if ft == "Avante" or not listed then
|
||||
return
|
||||
end
|
||||
|
||||
local curwin = vim.api.nvim_get_current_win()
|
||||
|
||||
sidebar.code.win = curwin
|
||||
sidebar.code.buf = curbuf
|
||||
sidebar:render()
|
||||
end
|
||||
|
||||
---@param opts? avante.Config
|
||||
function M.setup(opts)
|
||||
---PERF: we can still allow running require("avante").setup() multiple times to override config if users wish to
|
||||
|
@ -1,19 +1,16 @@
|
||||
--@class avante.Range
|
||||
--@field start table Selection start point
|
||||
--@field start.line number Line number of the selection start
|
||||
--@field start.col number Column number of the selection start
|
||||
--@field finish table Selection end point
|
||||
--@field finish.line number Line number of the selection end
|
||||
--@field finish.col number Column number of the selection end
|
||||
---@class avante.Range
|
||||
---@field start avante.RangeSelection start point
|
||||
---@field finish avante.RangeSelection Selection end point
|
||||
local Range = {}
|
||||
Range.__index = Range
|
||||
-- Create a selection range
|
||||
-- @param start table Selection start point
|
||||
-- @param start.line number Line number of the selection start
|
||||
-- @param start.col number Column number of the selection start
|
||||
-- @param finish table Selection end point
|
||||
-- @param finish.line number Line number of the selection end
|
||||
-- @param finish.col number Column number of the selection end
|
||||
|
||||
---@class avante.RangeSelection: table<string, integer>
|
||||
---@field line number
|
||||
---@field col number
|
||||
|
||||
---Create a selection range
|
||||
---@param start avante.RangeSelection Selection start point
|
||||
---@param finish avante.RangeSelection Selection end point
|
||||
function Range.new(start, finish)
|
||||
local self = setmetatable({}, Range)
|
||||
self.start = start
|
||||
|
@ -1,12 +1,12 @@
|
||||
--@class avante.SelectionResult
|
||||
--@field content string Selected content
|
||||
--@field range avante.Range Selection range
|
||||
---@class avante.SelectionResult
|
||||
---@field content string Selected content
|
||||
---@field range avante.Range Selection range
|
||||
local SelectionResult = {}
|
||||
SelectionResult.__index = SelectionResult
|
||||
|
||||
-- Create a selection content and range
|
||||
--@param content string Selected content
|
||||
--@param range avante.Range Selection range
|
||||
---@param content string Selected content
|
||||
---@param range avante.Range Selection range
|
||||
function SelectionResult.new(content, range)
|
||||
local self = setmetatable({}, SelectionResult)
|
||||
self.content = content
|
||||
|
@ -141,7 +141,7 @@ function Sidebar:intialize()
|
||||
|
||||
local filetype = api.nvim_get_option_value("filetype", { buf = self.code.buf })
|
||||
local selected_code_buf = self.renderer:get_component_by_id("selected_code").bufnr
|
||||
api.nvim_buf_set_option(selected_code_buf, "filetype", filetype)
|
||||
api.nvim_set_option_value("filetype", filetype, { buf = selected_code_buf })
|
||||
api.nvim_set_option_value("wrap", false, { win = self.renderer:get_component_by_id("selected_code").winid })
|
||||
|
||||
api.nvim_create_autocmd("BufEnter", {
|
||||
@ -209,24 +209,6 @@ function Sidebar:intialize()
|
||||
return self
|
||||
end
|
||||
|
||||
function Sidebar:refresh()
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
|
||||
local focused = self.view.buf == buf or self.bufnr.result == buf or self.bufnr.input == buf
|
||||
if focused or not self.view:is_open() then
|
||||
return
|
||||
end
|
||||
|
||||
local ft = vim.api.nvim_get_option_value("filetype", { buf = buf })
|
||||
local listed = vim.api.nvim_get_option_value("buflisted", { buf = buf })
|
||||
|
||||
if ft == "Avante" or not listed then
|
||||
return
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
---@param content string concatenated content of the buffer
|
||||
---@param focus? boolean whether to focus the result view
|
||||
function Sidebar:update_content(content, focus, callback)
|
||||
|
Loading…
x
Reference in New Issue
Block a user