2024-08-24 04:32:44 +08:00
|
|
|
---@class source
|
|
|
|
---@field sidebar avante.Sidebar
|
|
|
|
local source = {}
|
|
|
|
|
|
|
|
---@param sidebar avante.Sidebar
|
|
|
|
function source.new(sidebar)
|
2024-08-24 20:15:45 -04:00
|
|
|
---@type cmp.Source
|
2024-08-24 04:32:44 +08:00
|
|
|
return setmetatable({
|
|
|
|
sidebar = sidebar,
|
|
|
|
}, { __index = source })
|
|
|
|
end
|
|
|
|
|
2024-09-03 04:19:54 -04:00
|
|
|
function source:is_available() return vim.bo.filetype == "AvanteInput" end
|
2024-08-24 04:32:44 +08:00
|
|
|
|
2024-09-03 04:19:54 -04:00
|
|
|
source.get_position_encoding_kind = function() return "utf-8" end
|
2024-08-24 04:32:44 +08:00
|
|
|
|
2024-09-03 04:19:54 -04:00
|
|
|
function source:get_trigger_characters() return { "/" } end
|
2024-08-24 04:32:44 +08:00
|
|
|
|
2024-09-03 04:19:54 -04:00
|
|
|
function source:get_keyword_pattern() return [[\%(@\|#\|/\)\k*]] end
|
2024-08-24 04:32:44 +08:00
|
|
|
|
|
|
|
function source:complete(_, callback)
|
2024-08-24 04:35:33 +08:00
|
|
|
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, {
|
2024-08-25 01:59:22 -04:00
|
|
|
label = "/" .. command.command,
|
2024-08-24 04:32:44 +08:00
|
|
|
kind = kind,
|
2024-08-25 01:59:22 -04:00
|
|
|
detail = command.details,
|
2024-08-24 04:32:44 +08:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2024-09-03 05:12:07 -04:00
|
|
|
callback({
|
2024-08-24 04:32:44 +08:00
|
|
|
items = items,
|
|
|
|
isIncomplete = false,
|
2024-09-03 05:12:07 -04:00
|
|
|
})
|
2024-08-24 04:32:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
return source
|