chore(types): add annotations for block and refresh on winchanged (#40)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
parent
5d5ded5c55
commit
83402e4a2d
@ -42,6 +42,10 @@ M.defaults = {
|
|||||||
next = "]x",
|
next = "]x",
|
||||||
prev = "[x",
|
prev = "[x",
|
||||||
},
|
},
|
||||||
|
jump = {
|
||||||
|
next = "]]",
|
||||||
|
prev = "[[",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
windows = {
|
windows = {
|
||||||
width = 30, -- default % based on available width
|
width = 30, -- default % based on available width
|
||||||
|
@ -29,6 +29,7 @@ local Sidebar = {}
|
|||||||
---@field code avante.SidebarState
|
---@field code avante.SidebarState
|
||||||
---@field renderer NuiRenderer
|
---@field renderer NuiRenderer
|
||||||
---@field winid {result: integer, input: integer}
|
---@field winid {result: integer, input: integer}
|
||||||
|
---@field bufnr {result: integer, input: integer}
|
||||||
|
|
||||||
---@param id integer the tabpage id retrieved from vim.api.nvim_get_current_tabpage()
|
---@param id integer the tabpage id retrieved from vim.api.nvim_get_current_tabpage()
|
||||||
function Sidebar:new(id)
|
function Sidebar:new(id)
|
||||||
@ -36,6 +37,7 @@ function Sidebar:new(id)
|
|||||||
id = id,
|
id = id,
|
||||||
code = { buf = 0, win = 0, selection = nil },
|
code = { buf = 0, win = 0, selection = nil },
|
||||||
winid = { result = 0, input = 0 },
|
winid = { result = 0, input = 0 },
|
||||||
|
bufnr = { result = 0, input = 0 },
|
||||||
view = View:new(),
|
view = View:new(),
|
||||||
renderer = nil,
|
renderer = nil,
|
||||||
}, { __index = self })
|
}, { __index = self })
|
||||||
@ -60,6 +62,7 @@ end
|
|||||||
function Sidebar:reset()
|
function Sidebar:reset()
|
||||||
self.code = { buf = 0, win = 0 }
|
self.code = { buf = 0, win = 0 }
|
||||||
self.winid = { result = 0, input = 0 }
|
self.winid = { result = 0, input = 0 }
|
||||||
|
self.bufnr = { result = 0, input = 0 }
|
||||||
self:delete_autocmds()
|
self:delete_autocmds()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -109,15 +112,8 @@ function Sidebar:toggle()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Sidebar:has_code_win()
|
--- Initialize the sidebar instance.
|
||||||
return self.code.win
|
--- @return avante.Sidebar The Sidebar instance.
|
||||||
and self.code.buf
|
|
||||||
and self.code.win ~= 0
|
|
||||||
and self.code.buf ~= 0
|
|
||||||
and api.nvim_win_is_valid(self.code.win)
|
|
||||||
and api.nvim_buf_is_valid(self.code.buf)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Sidebar:intialize()
|
function Sidebar:intialize()
|
||||||
self.code.win = api.nvim_get_current_win()
|
self.code.win = api.nvim_get_current_win()
|
||||||
self.code.buf = api.nvim_get_current_buf()
|
self.code.buf = api.nvim_get_current_buf()
|
||||||
@ -139,6 +135,8 @@ function Sidebar:intialize()
|
|||||||
self.renderer:on_mount(function()
|
self.renderer:on_mount(function()
|
||||||
self.winid.result = self.renderer:get_component_by_id("result").winid
|
self.winid.result = self.renderer:get_component_by_id("result").winid
|
||||||
self.winid.input = self.renderer:get_component_by_id("input").winid
|
self.winid.input = self.renderer:get_component_by_id("input").winid
|
||||||
|
self.bufnr.result = vim.api.nvim_win_get_buf(self.winid.result)
|
||||||
|
self.bufnr.input = vim.api.nvim_win_get_buf(self.winid.input)
|
||||||
self.augroup = api.nvim_create_augroup("avante_" .. self.id .. self.view.win, { clear = true })
|
self.augroup = api.nvim_create_augroup("avante_" .. self.id .. self.view.win, { clear = true })
|
||||||
|
|
||||||
local filetype = api.nvim_get_option_value("filetype", { buf = self.code.buf })
|
local filetype = api.nvim_get_option_value("filetype", { buf = self.code.buf })
|
||||||
@ -207,6 +205,26 @@ function Sidebar:intialize()
|
|||||||
self:reset()
|
self:reset()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
---@param content string concatenated content of the buffer
|
---@param content string concatenated content of the buffer
|
||||||
@ -239,6 +257,12 @@ function Sidebar:update_content(content, focus, callback)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@class AvanteCodeblock
|
||||||
|
---@field start_line integer
|
||||||
|
---@field end_line integer
|
||||||
|
---@field lang string
|
||||||
|
|
||||||
|
---@return AvanteCodeblock[]
|
||||||
local function parse_codeblocks(buf)
|
local function parse_codeblocks(buf)
|
||||||
local codeblocks = {}
|
local codeblocks = {}
|
||||||
local in_codeblock = false
|
local in_codeblock = false
|
||||||
@ -527,6 +551,7 @@ function Sidebar:render()
|
|||||||
pcall(vim.keymap.del, "n", "A", { buffer = self.view.buf })
|
pcall(vim.keymap.del, "n", "A", { buffer = self.view.buf })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@type AvanteCodeblock[]
|
||||||
local codeblocks = {}
|
local codeblocks = {}
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
|
api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
|
||||||
@ -558,6 +583,7 @@ function Sidebar:render()
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
---@type NuiSignal
|
||||||
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)
|
||||||
|
@ -1,15 +1,33 @@
|
|||||||
---@meta
|
---@meta
|
||||||
|
|
||||||
|
---@class NuiSignalValue: boolean
|
||||||
|
local NuiSignalValue = require("nui-components.signal.value")
|
||||||
|
|
||||||
|
---@return boolean
|
||||||
|
function NuiSignalValue:negate() end
|
||||||
|
|
||||||
|
---@class NuiSignal
|
||||||
|
---@field is_loading boolean | NuiSignalValue
|
||||||
|
---@field text string
|
||||||
|
local AvanteSignal = require("nui-components.signal")
|
||||||
|
|
||||||
|
---@return any
|
||||||
|
function AvanteSignal:get_value() end
|
||||||
|
|
||||||
---@class NuiRenderer
|
---@class NuiRenderer
|
||||||
_G.AvanteRenderer = require("nui-components.renderer")
|
local AvanteRenderer = require("nui-components.renderer")
|
||||||
|
|
||||||
---@class NuiComponent
|
---@class NuiComponent
|
||||||
_G.AvanteComponent = require("nui-components.component")
|
---@field winid integer | nil
|
||||||
|
local AvanteComponent = require("nui-components.component")
|
||||||
|
|
||||||
---@param opts table<string, any>
|
---@param opts table<string, any>
|
||||||
---@return NuiRenderer
|
---@return NuiRenderer
|
||||||
function AvanteRenderer.create(opts) end
|
function AvanteRenderer.create(opts) end
|
||||||
|
|
||||||
|
---@return NuiComponent[]
|
||||||
|
function AvanteRenderer:get_focusable_components() end
|
||||||
|
|
||||||
---@param body fun():NuiComponent
|
---@param body fun():NuiComponent
|
||||||
function AvanteRenderer:render(body) end
|
function AvanteRenderer:render(body) end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user