Skip to content

Commit d8a593d

Browse files
committed
fix: snippets items
1 parent 7568de9 commit d8a593d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lua/blink/cmp/sources/snippets/init.lua

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ function snippets:get_completions(context, callback)
2929
local ft_snippets = self.registry:get_snippets_for_ft(filetype)
3030
local snips = vim.tbl_deep_extend('force', {}, global_snippets, extended_snippets, ft_snippets)
3131

32-
self.cache[filetype] = vim.tbl_map(
33-
function(snippet) return self.registry:snippet_to_completion_item(snippet) end,
34-
snips
35-
)
32+
self.cache[filetype] = {}
33+
for _, snippet in pairs(snips) do
34+
table.insert(self.cache[filetype], self.registry:snippet_to_completion_item(snippet))
35+
end
36+
vim.print(self.cache[filetype])
3637
end
3738

3839
callback({

lua/blink/cmp/sources/snippets/registry.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
---@class blink.cmp.Snippet
66
---@field prefix string
7-
---@field body string
7+
---@field body string[]
88
---@field description? string
99

1010
local registry = {
@@ -49,7 +49,9 @@ function registry:get_snippets_for_ft(filetype)
4949
local snippets = vim.json.decode(contents)
5050
for _, key in ipairs(vim.tbl_keys(snippets)) do
5151
local snippet = utils.read_snippet(snippets[key], key)
52-
loaded_snippets = vim.tbl_deep_extend('force', {}, loaded_snippets, snippet)
52+
for snippet_name, snippet_def in pairs(snippet) do
53+
loaded_snippets[snippet_name] = snippet_def
54+
end
5355
end
5456
end
5557
end
@@ -59,7 +61,9 @@ function registry:get_snippets_for_ft(filetype)
5961
local snippets = vim.json.decode(contents)
6062
for _, key in ipairs(vim.tbl_keys(snippets)) do
6163
local snippet = utils.read_snippet(snippets[key], key)
62-
loaded_snippets = vim.tbl_deep_extend('force', {}, loaded_snippets, snippet)
64+
for key, snippet in pairs(snippet) do
65+
loaded_snippets[key] = snippet
66+
end
6367
end
6468
end
6569
end
@@ -107,7 +111,7 @@ function registry:snippet_to_completion_item(snippet)
107111
kind = vim.lsp.protocol.CompletionItemKind.Snippet,
108112
label = snippet.prefix,
109113
insertTextFormat = vim.lsp.protocol.InsertTextFormat.Snippet,
110-
insertText = snippet.body,
114+
insertText = table.concat(snippet.body, '\n'),
111115
description = snippet.description,
112116
}
113117
end

0 commit comments

Comments
 (0)