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 = {
|
mappings = {
|
||||||
ask = "<leader>aa",
|
ask = "<leader>aa",
|
||||||
edit = "<leader>ae",
|
edit = "<leader>ae",
|
||||||
|
refresh = "<leader>ar",
|
||||||
diff = {
|
diff = {
|
||||||
ours = "co",
|
ours = "co",
|
||||||
theirs = "ct",
|
theirs = "ct",
|
||||||
|
@ -34,10 +34,14 @@ H.commands = function()
|
|||||||
end
|
end
|
||||||
sidebar:close()
|
sidebar:close()
|
||||||
end, { desc = "avante: close chat window" })
|
end, { desc = "avante: close chat window" })
|
||||||
|
cmd("Refresh", function()
|
||||||
|
M.refresh()
|
||||||
|
end, { desc = "avante: refresh windows" })
|
||||||
end
|
end
|
||||||
|
|
||||||
H.keymaps = function()
|
H.keymaps = function()
|
||||||
vim.keymap.set({ "n", "v" }, Config.mappings.ask, M.toggle, { noremap = true })
|
vim.keymap.set({ "n", "v" }, Config.mappings.ask, M.toggle, { noremap = true })
|
||||||
|
vim.keymap.set("n", Config.mappings.refresh, M.refresh, { noremap = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
H.autocmds = function()
|
H.autocmds = function()
|
||||||
@ -123,6 +127,32 @@ M.toggle = function()
|
|||||||
return sidebar:toggle()
|
return sidebar:toggle()
|
||||||
end
|
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
|
---@param opts? avante.Config
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
---PERF: we can still allow running require("avante").setup() multiple times to override config if users wish to
|
---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
|
---@class avante.Range
|
||||||
--@field start table Selection start point
|
---@field start avante.RangeSelection start point
|
||||||
--@field start.line number Line number of the selection start
|
---@field finish avante.RangeSelection Selection end point
|
||||||
--@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
|
|
||||||
local Range = {}
|
local Range = {}
|
||||||
Range.__index = Range
|
Range.__index = Range
|
||||||
-- Create a selection range
|
|
||||||
-- @param start table Selection start point
|
---@class avante.RangeSelection: table<string, integer>
|
||||||
-- @param start.line number Line number of the selection start
|
---@field line number
|
||||||
-- @param start.col number Column number of the selection start
|
---@field col number
|
||||||
-- @param finish table Selection end point
|
|
||||||
-- @param finish.line number Line number of the selection end
|
---Create a selection range
|
||||||
-- @param finish.col number Column number of the selection end
|
---@param start avante.RangeSelection Selection start point
|
||||||
|
---@param finish avante.RangeSelection Selection end point
|
||||||
function Range.new(start, finish)
|
function Range.new(start, finish)
|
||||||
local self = setmetatable({}, Range)
|
local self = setmetatable({}, Range)
|
||||||
self.start = start
|
self.start = start
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
--@class avante.SelectionResult
|
---@class avante.SelectionResult
|
||||||
--@field content string Selected content
|
---@field content string Selected content
|
||||||
--@field range avante.Range Selection range
|
---@field range avante.Range Selection range
|
||||||
local SelectionResult = {}
|
local SelectionResult = {}
|
||||||
SelectionResult.__index = SelectionResult
|
SelectionResult.__index = SelectionResult
|
||||||
|
|
||||||
-- Create a selection content and range
|
-- Create a selection content and range
|
||||||
--@param content string Selected content
|
---@param content string Selected content
|
||||||
--@param range avante.Range Selection range
|
---@param range avante.Range Selection range
|
||||||
function SelectionResult.new(content, range)
|
function SelectionResult.new(content, range)
|
||||||
local self = setmetatable({}, SelectionResult)
|
local self = setmetatable({}, SelectionResult)
|
||||||
self.content = content
|
self.content = content
|
||||||
|
@ -141,7 +141,7 @@ function Sidebar:intialize()
|
|||||||
|
|
||||||
local filetype = api.nvim_get_option_value("filetype", { buf = self.code.buf })
|
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
|
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_set_option_value("wrap", false, { win = self.renderer:get_component_by_id("selected_code").winid })
|
||||||
|
|
||||||
api.nvim_create_autocmd("BufEnter", {
|
api.nvim_create_autocmd("BufEnter", {
|
||||||
@ -209,24 +209,6 @@ function Sidebar:intialize()
|
|||||||
return self
|
return self
|
||||||
end
|
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 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, callback)
|
function Sidebar:update_content(content, focus, callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user