fix: align lua oop (#889)
This commit is contained in:
parent
da41105fc8
commit
9d0e1cd4af
@ -18,6 +18,7 @@ local Utils = require("avante.utils")
|
||||
---@field spinner_timer uv_timer_t | nil
|
||||
---@field spinner_active boolean
|
||||
local PromptInput = {}
|
||||
PromptInput.__index = PromptInput
|
||||
|
||||
---@class PromptInputOptions
|
||||
---@field start_insert? boolean
|
||||
@ -29,7 +30,7 @@ local PromptInput = {}
|
||||
---@param opts? PromptInputOptions
|
||||
function PromptInput:new(opts)
|
||||
opts = opts or {}
|
||||
local obj = setmetatable({}, { __index = self })
|
||||
local obj = setmetatable({}, PromptInput)
|
||||
obj.bufnr = nil
|
||||
obj.winid = nil
|
||||
obj.shortcuts_hints_winid = nil
|
||||
@ -235,6 +236,7 @@ function PromptInput:setup_keymaps()
|
||||
local bufnr = self.bufnr
|
||||
|
||||
local function get_input()
|
||||
if not bufnr or not api.nvim_buf_is_valid(bufnr) then return "" end
|
||||
local lines = api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
return lines[1] or ""
|
||||
end
|
||||
|
@ -11,11 +11,11 @@ Range.__index = Range
|
||||
---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
|
||||
self.finish = finish
|
||||
return self
|
||||
function Range:new(start, finish)
|
||||
local instance = setmetatable({}, Range)
|
||||
instance.start = start
|
||||
instance.finish = finish
|
||||
return instance
|
||||
end
|
||||
|
||||
return Range
|
||||
|
@ -21,6 +21,7 @@ local PRIORITY = vim.highlight.priorities.user
|
||||
---@field code_winid integer | nil
|
||||
---@field prompt_input PromptInput | nil
|
||||
local Selection = {}
|
||||
Selection.__index = Selection
|
||||
|
||||
Selection.did_setup = false
|
||||
|
||||
@ -34,7 +35,7 @@ function Selection:new(id)
|
||||
cursor_pos = nil,
|
||||
code_winid = nil,
|
||||
prompt_input = nil,
|
||||
}, { __index = self })
|
||||
}, Selection)
|
||||
end
|
||||
|
||||
function Selection:get_virt_text_line()
|
||||
@ -238,7 +239,7 @@ function Selection:create_editing_input()
|
||||
if has_cmp then
|
||||
cmp.register_source(
|
||||
"avante_mentions",
|
||||
require("cmp_avante.mentions").new(Utils.get_mentions(), prompt_input.bufnr)
|
||||
require("cmp_avante.mentions"):new(Utils.get_mentions(), prompt_input.bufnr)
|
||||
)
|
||||
cmp.setup.buffer({
|
||||
enabled = true,
|
||||
|
@ -7,11 +7,11 @@ SelectionResult.__index = SelectionResult
|
||||
-- Create a selection content and range
|
||||
---@param content string Selected content
|
||||
---@param range avante.Range Selection range
|
||||
function SelectionResult.new(content, range)
|
||||
local self = setmetatable({}, SelectionResult)
|
||||
self.content = content
|
||||
self.range = range
|
||||
return self
|
||||
function SelectionResult:new(content, range)
|
||||
local instance = setmetatable({}, SelectionResult)
|
||||
instance.content = content
|
||||
instance.range = range
|
||||
return instance
|
||||
end
|
||||
|
||||
return SelectionResult
|
||||
|
@ -1653,11 +1653,11 @@ function Sidebar:create_input(opts)
|
||||
if has_cmp then
|
||||
cmp.register_source(
|
||||
"avante_commands",
|
||||
require("cmp_avante.commands").new(self:get_commands(), self.input.bufnr)
|
||||
require("cmp_avante.commands"):new(self:get_commands(), self.input.bufnr)
|
||||
)
|
||||
cmp.register_source(
|
||||
"avante_mentions",
|
||||
require("cmp_avante.mentions").new(Utils.get_mentions(), self.input.bufnr)
|
||||
require("cmp_avante.mentions"):new(Utils.get_mentions(), self.input.bufnr)
|
||||
)
|
||||
cmp.setup.buffer({
|
||||
enabled = true,
|
||||
|
@ -190,7 +190,7 @@ function M.get_visual_selection_and_range()
|
||||
start_col, end_col = end_col, start_col
|
||||
end
|
||||
local content = "" -- luacheck: ignore
|
||||
local range = Range.new({ line = start_line, col = start_col }, { line = end_line, col = end_col })
|
||||
local range = Range:new({ line = start_line, col = start_col }, { line = end_line, col = end_col })
|
||||
-- Check if it's a single-line selection
|
||||
if start_line == end_line then
|
||||
-- Get partial content of a single line
|
||||
@ -213,7 +213,7 @@ function M.get_visual_selection_and_range()
|
||||
end
|
||||
if not content then return nil end
|
||||
-- Return the selected content and range
|
||||
return SelectionResult.new(content, range)
|
||||
return SelectionResult:new(content, range)
|
||||
end
|
||||
|
||||
---Wrapper around `api.nvim_buf_get_lines` which defaults to the current buffer
|
||||
|
@ -1,18 +1,20 @@
|
||||
local api = vim.api
|
||||
|
||||
---@class commands_source
|
||||
---@class commands_source : cmp.Source
|
||||
---@field commands AvanteSlashCommand[]
|
||||
---@field bufnr integer
|
||||
local commands_source = {}
|
||||
commands_source.__index = commands_source
|
||||
|
||||
---@param commands AvanteSlashCommand[]
|
||||
---@param bufnr integer
|
||||
function commands_source.new(commands, bufnr)
|
||||
---@type cmp.Source
|
||||
return setmetatable({
|
||||
commands = commands,
|
||||
bufnr = bufnr,
|
||||
}, { __index = commands_source })
|
||||
function commands_source:new(commands, bufnr)
|
||||
local instance = setmetatable({}, commands_source)
|
||||
|
||||
instance.commands = commands
|
||||
instance.bufnr = bufnr
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
function commands_source:is_available() return api.nvim_get_current_buf() == self.bufnr end
|
||||
|
@ -1,18 +1,20 @@
|
||||
local api = vim.api
|
||||
|
||||
---@class mentions_source
|
||||
---@class mentions_source : cmp.Source
|
||||
---@field mentions {description: string, command: AvanteMentions, details: string, shorthelp?: string, callback?: AvanteMentionCallback}[]
|
||||
---@field bufnr integer
|
||||
local mentions_source = {}
|
||||
mentions_source.__index = mentions_source
|
||||
|
||||
---@param mentions {description: string, command: AvanteMentions, details: string, shorthelp?: string, callback?: AvanteMentionCallback}[]
|
||||
---@param bufnr integer
|
||||
function mentions_source.new(mentions, bufnr)
|
||||
---@type cmp.Source
|
||||
return setmetatable({
|
||||
mentions = mentions,
|
||||
bufnr = bufnr,
|
||||
}, { __index = mentions_source })
|
||||
function mentions_source:new(mentions, bufnr)
|
||||
local instance = setmetatable({}, mentions_source)
|
||||
|
||||
instance.mentions = mentions
|
||||
instance.bufnr = bufnr
|
||||
|
||||
return instance
|
||||
end
|
||||
|
||||
function mentions_source:is_available() return api.nvim_get_current_buf() == self.bufnr end
|
||||
|
Loading…
x
Reference in New Issue
Block a user