Skip to content

Commit e2a0f9f

Browse files
authored
chore(completion): blink cmp fine tuning (#140)
* chore(completion): remove unused variable - Delete unused triggers variable from get_trigger_characters - Simplify code without functional changes - Improve code cleanliness * fix(completion): fix blink_cmp filtering and async support - Rename is_available to enabled per blink_cmp API - Implement filterText for proper fuzzy matching - Add async flag to source provider configuration - Improve insert text fallback handling
1 parent 6094564 commit e2a0f9f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lua/opencode/ui/completion/engines/blink_cmp.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ function Source:get_trigger_characters()
1414
local mention_key = config.get_key_for_function('input_window', 'mention')
1515
local slash_key = config.get_key_for_function('input_window', 'slash_commands')
1616
local context_key = config.get_key_for_function('input_window', 'context_items')
17-
local triggers = {}
1817
return {
1918
slash_key or '',
2019
mention_key or '',
2120
context_key or '',
2221
}
2322
end
2423

25-
function Source:is_available()
24+
function Source:enabled()
2625
return vim.bo.filetype == 'opencode'
2726
end
2827

@@ -44,7 +43,7 @@ function Source:get_completions(ctx, callback)
4443
end
4544

4645
local context = {
47-
input = trigger_match,
46+
input = trigger_match, -- Pass input for search-based sources (e.g., files)
4847
cursor_pos = col,
4948
line = line,
5049
trigger_char = trigger_char,
@@ -54,14 +53,17 @@ function Source:get_completions(ctx, callback)
5453
for _, completion_source in ipairs(completion_sources) do
5554
local source_items = completion_source.complete(context):await()
5655
for i, item in ipairs(source_items) do
56+
local insert_text = item.insert_text or item.label
5757
table.insert(items, {
5858
label = item.label,
5959
kind = item.kind,
6060
kind_icon = item.kind_icon,
6161
kind_hl = item.kind_hl,
6262
detail = item.detail,
6363
documentation = item.documentation,
64-
insertText = item.insert_text or item.label,
64+
-- Use filterText for fuzzy matching against the typed text after trigger char
65+
filterText = item.filter_text or item.label,
66+
insertText = insert_text,
6567
sortText = string.format(
6668
'%02d_%02d_%02d_%s',
6769
completion_source.priority or 999,
@@ -101,6 +103,7 @@ function M.setup(completion_sources)
101103

102104
blink.add_source_provider('opencode_mentions', {
103105
module = 'opencode.ui.completion.engines.blink_cmp',
106+
async = true,
104107
})
105108

106109
return true

0 commit comments

Comments
 (0)