refactor(cmp): Extract get_chat_mentions for third-party cmp source usage (#2027)
This commit is contained in:
@@ -492,35 +492,7 @@ function M.setup(opts)
|
|||||||
if has_cmp then
|
if has_cmp then
|
||||||
cmp.register_source("avante_commands", require("cmp_avante.commands"):new())
|
cmp.register_source("avante_commands", require("cmp_avante.commands"):new())
|
||||||
|
|
||||||
cmp.register_source(
|
cmp.register_source("avante_mentions", require("cmp_avante.mentions"):new(Utils.get_chat_mentions))
|
||||||
"avante_mentions",
|
|
||||||
require("cmp_avante.mentions"):new(function()
|
|
||||||
local mentions = Utils.get_mentions()
|
|
||||||
|
|
||||||
table.insert(mentions, {
|
|
||||||
description = "file",
|
|
||||||
command = "file",
|
|
||||||
details = "add files...",
|
|
||||||
callback = function(sidebar) sidebar.file_selector:open() end,
|
|
||||||
})
|
|
||||||
|
|
||||||
table.insert(mentions, {
|
|
||||||
description = "quickfix",
|
|
||||||
command = "quickfix",
|
|
||||||
details = "add files in quickfix list to chat context",
|
|
||||||
callback = function(sidebar) sidebar.file_selector:add_quickfix_files() end,
|
|
||||||
})
|
|
||||||
|
|
||||||
table.insert(mentions, {
|
|
||||||
description = "buffers",
|
|
||||||
command = "buffers",
|
|
||||||
details = "add open buffers to the chat context",
|
|
||||||
callback = function(sidebar) sidebar.file_selector:add_buffer_files() end,
|
|
||||||
})
|
|
||||||
|
|
||||||
return mentions
|
|
||||||
end)
|
|
||||||
)
|
|
||||||
|
|
||||||
cmp.register_source("avante_prompt_mentions", require("cmp_avante.mentions"):new(Utils.get_mentions))
|
cmp.register_source("avante_prompt_mentions", require("cmp_avante.mentions"):new(Utils.get_mentions))
|
||||||
|
|
||||||
|
|||||||
@@ -452,3 +452,7 @@ vim.g.avante_login = vim.g.avante_login
|
|||||||
---@field details string
|
---@field details string
|
||||||
---@field shorthelp? string
|
---@field shorthelp? string
|
||||||
---@field callback? AvanteSlashCommandCallback
|
---@field callback? AvanteSlashCommandCallback
|
||||||
|
|
||||||
|
---@alias AvanteMentions "codebase" | "diagnostics" | "file" | "quickfix" | "buffers"
|
||||||
|
---@alias AvanteMentionCallback fun(args: string, cb?: fun(args: string): nil): nil
|
||||||
|
---@alias AvanteMention {description: string, command: AvanteMentions, details: string, shorthelp?: string, callback?: AvanteMentionCallback}
|
||||||
|
|||||||
@@ -913,9 +913,6 @@ function M.extract_mentions(content)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
---@alias AvanteMentions "codebase" | "diagnostics"
|
|
||||||
---@alias AvanteMentionCallback fun(args: string, cb?: fun(args: string): nil): nil
|
|
||||||
---@alias AvanteMention {description: string, command: AvanteMentions, details: string, shorthelp?: string, callback?: AvanteMentionCallback}
|
|
||||||
---@return AvanteMention[]
|
---@return AvanteMention[]
|
||||||
function M.get_mentions()
|
function M.get_mentions()
|
||||||
return {
|
return {
|
||||||
@@ -932,6 +929,34 @@ function M.get_mentions()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return AvanteMention[]
|
||||||
|
function M.get_chat_mentions()
|
||||||
|
local mentions = M.get_mentions()
|
||||||
|
|
||||||
|
table.insert(mentions, {
|
||||||
|
description = "file",
|
||||||
|
command = "file",
|
||||||
|
details = "add files...",
|
||||||
|
callback = function(sidebar) sidebar.file_selector:open() end,
|
||||||
|
})
|
||||||
|
|
||||||
|
table.insert(mentions, {
|
||||||
|
description = "quickfix",
|
||||||
|
command = "quickfix",
|
||||||
|
details = "add files in quickfix list to chat context",
|
||||||
|
callback = function(sidebar) sidebar.file_selector:add_quickfix_files() end,
|
||||||
|
})
|
||||||
|
|
||||||
|
table.insert(mentions, {
|
||||||
|
description = "buffers",
|
||||||
|
command = "buffers",
|
||||||
|
details = "add open buffers to the chat context",
|
||||||
|
callback = function(sidebar) sidebar.file_selector:add_buffer_files() end,
|
||||||
|
})
|
||||||
|
|
||||||
|
return mentions
|
||||||
|
end
|
||||||
|
|
||||||
---@param path string
|
---@param path string
|
||||||
---@param set_current_buf? boolean
|
---@param set_current_buf? boolean
|
||||||
---@return integer bufnr
|
---@return integer bufnr
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
||||||
---@class mentions_source : cmp.Source
|
---@class mentions_source : cmp.Source
|
||||||
---@field get_mentions fun(): {description: string, command: AvanteMentions, details: string, shorthelp?: string, callback?: AvanteMentionCallback}[]
|
---@field get_mentions fun(): AvanteMention[]
|
||||||
local MentionsSource = {}
|
local MentionsSource = {}
|
||||||
MentionsSource.__index = MentionsSource
|
MentionsSource.__index = MentionsSource
|
||||||
|
|
||||||
---@param get_mentions fun(): {description: string, command: AvanteMentions, details: string, shorthelp?: string, callback?: AvanteMentionCallback}[]
|
---@param get_mentions fun(): AvanteMention[]
|
||||||
function MentionsSource:new(get_mentions)
|
function MentionsSource:new(get_mentions)
|
||||||
local instance = setmetatable({}, MentionsSource)
|
local instance = setmetatable({}, MentionsSource)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user