43 lines
925 B
Lua
Raw Normal View History

2024-08-24 04:32:44 +08:00
---@class source
---@field sidebar avante.Sidebar
local source = {}
---@param sidebar avante.Sidebar
function source.new(sidebar)
---@type cmp.Source
2024-08-24 04:32:44 +08:00
return setmetatable({
sidebar = sidebar,
}, { __index = source })
end
function source:is_available() return vim.bo.filetype == "AvanteInput" end
2024-08-24 04:32:44 +08:00
source.get_position_encoding_kind = function() return "utf-8" end
2024-08-24 04:32:44 +08:00
function source:get_trigger_characters() return { "/" } end
2024-08-24 04:32:44 +08:00
function source:get_keyword_pattern() return [[\%(@\|#\|/\)\k*]] end
2024-08-24 04:32:44 +08:00
function source:complete(_, callback)
local kind = require("cmp").lsp.CompletionItemKind.Variable
2024-08-24 04:32:44 +08:00
local items = {}
local commands = self.sidebar:get_commands()
for _, command in ipairs(commands) do
table.insert(items, {
label = "/" .. command.command,
2024-08-24 04:32:44 +08:00
kind = kind,
detail = command.details,
2024-08-24 04:32:44 +08:00
})
end
callback {
2024-08-24 04:32:44 +08:00
items = items,
isIncomplete = false,
}
2024-08-24 04:32:44 +08:00
end
return source