Skip to content

Commit 3dc3821

Browse files
committed
fix(blink): improve provider override logic and path completion handling
This should improve #205
1 parent d391ee8 commit 3dc3821

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ end
1616
---Check if blink-cmp is available
1717
---@return boolean
1818
function BlinkCmpEngine:is_available()
19-
local ok = pcall(require, 'blink.cmp')
20-
return ok and CompletionEngine.is_available()
19+
return pcall(require, 'blink.cmp') and CompletionEngine.is_available()
2120
end
2221

2322
---Setup blink-cmp completion engine
@@ -36,7 +35,6 @@ function BlinkCmpEngine:setup(completion_sources)
3635
async = true,
3736
})
3837

39-
-- Hide blink-cmp menu on certain trigger characters when opened via other completion sources
4038
vim.api.nvim_create_autocmd('User', {
4139
group = vim.api.nvim_create_augroup('OpencodeBlinkCmp', { clear = true }),
4240
pattern = 'BlinkCmpMenuOpen',
@@ -49,10 +47,18 @@ function BlinkCmpEngine:setup(completion_sources)
4947

5048
local blink = require('blink.cmp')
5149
local ctx = blink.get_context()
52-
5350
local triggers = CompletionEngine.get_trigger_characters()
54-
if ctx.trigger.initial_kind == 'trigger_character' and vim.tbl_contains(triggers, ctx.trigger.character) then
55-
blink.hide()
51+
52+
-- blink has a tendency to show other providers even when we want only our own.
53+
local should_override = (
54+
ctx.trigger.initial_kind == 'trigger_character' and vim.tbl_contains(triggers, ctx.trigger.character)
55+
) or (ctx.trigger.initial_kind == 'keyword' and vim.tbl_contains(triggers, ctx.line:sub(1, 1)))
56+
57+
if should_override then
58+
blink.show({
59+
providers = { 'opencode_mentions' },
60+
trigger_character = ctx.trigger.character,
61+
})
5662
end
5763
end,
5864
})
@@ -62,8 +68,8 @@ end
6268
---Check if blink-cmp completion menu is visible
6369
---@return boolean
6470
function BlinkCmpEngine:is_visible()
65-
local ok, blink = pcall(require, 'blink.cmp')
66-
return ok and blink.is_visible()
71+
local blink = require('blink.cmp')
72+
return blink.is_visible()
6773
end
6874

6975
---Trigger completion manually for blink-cmp
@@ -83,10 +89,7 @@ function BlinkCmpEngine:trigger(trigger_char)
8389
end
8490

8591
function BlinkCmpEngine:hide()
86-
local blink = require('blink.cmp')
87-
if blink.is_visible() then
88-
blink.hide()
89-
end
92+
require('blink.cmp').hide()
9093
end
9194

9295
-- Source implementation for blink-cmp provider (when this module is loaded by blink.cmp)
@@ -157,7 +160,7 @@ function Source:get_completions(ctx, callback)
157160
end)
158161
end
159162

160-
function Source:execute(ctx, item, callback, default_implementation)
163+
function Source:execute(_, item, callback, default_implementation)
161164
default_implementation()
162165

163166
if item.data and item.data.original_item then

0 commit comments

Comments
 (0)