feat: commands with cmp (#183)
This commit is contained in:
49
lua/cmp_avante/commands.lua
Normal file
49
lua/cmp_avante/commands.lua
Normal file
@@ -0,0 +1,49 @@
|
||||
---@class source
|
||||
---@field sidebar avante.Sidebar
|
||||
local source = {}
|
||||
|
||||
---@param sidebar avante.Sidebar
|
||||
function source.new(sidebar)
|
||||
return setmetatable({
|
||||
sidebar = sidebar,
|
||||
}, { __index = source })
|
||||
end
|
||||
|
||||
function source:is_available()
|
||||
return vim.bo.filetype == "AvanteInput"
|
||||
end
|
||||
|
||||
source.get_position_encoding_kind = function()
|
||||
return "utf-8"
|
||||
end
|
||||
|
||||
function source:get_trigger_characters()
|
||||
return { "/" }
|
||||
end
|
||||
|
||||
function source:get_keyword_pattern()
|
||||
return [[\%(@\|#\|/\)\k*]]
|
||||
end
|
||||
|
||||
function source:complete(_, callback)
|
||||
local kind = require("cmp").lsp.CompletionItemKind.Function
|
||||
|
||||
local items = {}
|
||||
|
||||
local commands = self.sidebar:get_commands()
|
||||
|
||||
for _, command in ipairs(commands) do
|
||||
table.insert(items, {
|
||||
label = "/" .. command.name,
|
||||
kind = kind,
|
||||
detail = command.description,
|
||||
})
|
||||
end
|
||||
|
||||
callback({
|
||||
items = items,
|
||||
isIncomplete = false,
|
||||
})
|
||||
end
|
||||
|
||||
return source
|
||||
Reference in New Issue
Block a user