avante.nvim/lua/cmp_avante/commands.lua
yetone 8e1018fef7
feat: repo map (#496)
* feat: repo map

* chore: remove breakline

* chore: remove spaces

* fix: golang public method

* feat: mentions for editing input
2024-09-23 18:52:26 +08:00

43 lines
1016 B
Lua

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