fix: filter out completions to relevant completion source (#2769)

This commit is contained in:
Peter Cardenas
2025-10-15 03:43:25 -07:00
committed by GitHub
parent e1be2d21b7
commit 250b7a26b4
3 changed files with 30 additions and 3 deletions

View File

@@ -18,7 +18,16 @@ function CommandsSource:get_trigger_characters() return { "/" } end
function CommandsSource:get_keyword_pattern() return [[\%(@\|#\|/\)\k*]] end
function CommandsSource:complete(_, callback)
---@param params cmp.SourceCompletionApiParams
function CommandsSource:complete(params, callback)
---@type string?
local trigger_character
if params.completion_context.triggerKind == 1 then
trigger_character = string.match(params.context.cursor_before_line, "%s*(/)%S*$")
elseif params.completion_context.triggerKind == 2 then
trigger_character = params.completion_context.triggerCharacter
end
if not trigger_character or trigger_character ~= "/" then return callback({ items = {}, isIncomplete = false }) end
local Utils = require("avante.utils")
local kind = require("cmp").lsp.CompletionItemKind.Variable
local commands = Utils.get_commands()