File tree 2 files changed +10
-14
lines changed
lua/blink/cmp/sources/snippets
2 files changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -29,27 +29,24 @@ function snippets:get_completions(_, callback)
29
29
30
30
self .cache [filetype ] = {}
31
31
for _ , snippet in pairs (snips ) do
32
- table.insert (self .cache [filetype ], self . registry : snippet_to_completion_item ( snippet ) )
32
+ table.insert (self .cache [filetype ], snippet )
33
33
end
34
34
end
35
35
36
- local copied_items = vim .tbl_map (function (item ) return utils .shallow_copy (item ) end , self .cache [filetype ])
36
+ local items = vim .tbl_map (
37
+ function (item ) return self .registry :snippet_to_completion_item (item ) end ,
38
+ self .cache [filetype ]
39
+ )
37
40
callback ({
38
41
is_incomplete_forward = false ,
39
42
is_incomplete_backward = false ,
40
- items = copied_items ,
43
+ items = items ,
41
44
})
42
45
end
43
46
44
47
function snippets :resolve (item , callback )
45
48
-- TODO: ideally context is passed with the filetype
46
- local documentation = ' ```'
47
- .. vim .bo .filetype
48
- .. ' \n '
49
- .. self .registry :preview (item .insertText )
50
- .. ' ```'
51
- .. ' \n ---\n '
52
- .. item .description
49
+ local documentation = ' ```' .. vim .bo .filetype .. ' \n ' .. item .insertText .. ' ```' .. ' \n ---\n ' .. item .description
53
50
54
51
local resolved_item = vim .deepcopy (item )
55
52
resolved_item .documentation = {
Original file line number Diff line number Diff line change @@ -103,22 +103,21 @@ function registry:get_global_snippets()
103
103
end
104
104
105
105
--- @param snippet blink.cmp.Snippet
106
- --- @param filetype string
107
- --- @param include_documentation boolean
108
106
--- @return blink.cmp.CompletionItem
109
107
function registry :snippet_to_completion_item (snippet )
108
+ local body = type (snippet .body ) == ' string' and snippet .body or table.concat (snippet .body , ' \n ' )
110
109
return {
111
110
kind = vim .lsp .protocol .CompletionItemKind .Snippet ,
112
111
label = snippet .prefix ,
113
112
insertTextFormat = vim .lsp .protocol .InsertTextFormat .Snippet ,
114
- insertText = type ( snippet . body ) == ' string ' and snippet . body or table.concat ( snippet . body , ' \n ' ),
113
+ insertText = self : parse_body ( body ),
115
114
description = snippet .description ,
116
115
}
117
116
end
118
117
119
118
--- @param snippet string
120
119
--- @return string
121
- function registry :preview (snippet )
120
+ function registry :parse_body (snippet )
122
121
local parse = utils .safe_parse (self :expand_vars (snippet ))
123
122
return parse and tostring (parse ) or snippet
124
123
end
You can’t perform that action at this time.
0 commit comments