Skip to content

Commit ded1fb1

Browse files
committed
snippet completion support fuzzy and use prefix
1 parent 9805468 commit ded1fb1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lua/phoenix/init.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,14 @@ function Snippet:get_completions(prefix)
534534

535535
local snippets = self.cache[ft]
536536
for trigger, snippet_data in pairs(snippets) do
537-
if vim.startswith(trigger:lower(), prefix:lower()) then
537+
local snippet_prefix = snippet_data.prefix
538+
if
539+
vim.startswith(snippet_prefix:lower(), prefix:lower())
540+
or (
541+
vim.o.completeopt:find('fuzzy')
542+
and next(vim.fn.matchfuzzy({ snippet_prefix }, prefix:lower())) ~= nil
543+
)
544+
then
538545
local body = snippet_data.body
539546
local insert_text = body
540547

@@ -543,8 +550,9 @@ function Snippet:get_completions(prefix)
543550
end
544551

545552
table.insert(results, {
546-
label = trigger,
553+
label = snippet_prefix,
547554
kind = 15,
555+
filterText = snippet_prefix,
548556
insertText = insert_text,
549557
documentation = {
550558
kind = 'markdown',

0 commit comments

Comments
 (0)