2
2
3
3
--- @class blink.cmp.MiniSnippetsSourceOptions
4
4
--- @field use_items_cache ? boolean completion items are cached using default mini.snippets context
5
+ --- @field use_label_description ? boolean Whether to put the snippet description in the label description
5
6
6
7
--- @class blink.cmp.MiniSnippetsSource : blink.cmp.Source
7
8
--- @field config blink.cmp.MiniSnippetsSourceOptions
@@ -19,6 +20,8 @@ local source = {}
19
20
local defaults_config = {
20
21
--- Whether to use a cache for completion items
21
22
use_items_cache = true ,
23
+ --- Whether to put the snippet description in the label description
24
+ use_label_description = false ,
22
25
}
23
26
24
27
function source .new (opts )
@@ -29,6 +32,7 @@ function source.new(opts)
29
32
' boolean' ,
30
33
' use_items_cache must be a boolean when using mini__snippets preset' ,
31
34
},
35
+ use_label_description = { config .use_label_description , ' boolean' },
32
36
}, opts )
33
37
34
38
local self = setmetatable ({}, { __index = source })
@@ -42,7 +46,7 @@ function source:enabled()
42
46
return _G .MiniSnippets ~= nil -- ensure that user has explicitly setup mini.snippets
43
47
end
44
48
45
- local function to_completion_items (snippets )
49
+ local function to_completion_items (snippets , use_label_description )
46
50
local result = {}
47
51
48
52
for _ , snip in ipairs (snippets ) do
@@ -53,6 +57,7 @@ local function to_completion_items(snippets)
53
57
insertText = snip .prefix ,
54
58
insertTextFormat = vim .lsp .protocol .InsertTextFormat .Snippet ,
55
59
data = { snip = snip },
60
+ labelDetails = snip .desc and use_label_description and { description = snip .desc } or nil ,
56
61
}
57
62
table.insert (result , item )
58
63
end
67
72
-- See :h MiniSnippets.default_prepare
68
73
--
69
74
-- Return completion items produced from snippets either directly or from cache
70
- local function get_completion_items (cache )
71
- if not cache then return to_completion_items (MiniSnippets .expand ({ match = false , insert = false })) end
75
+ local function get_completion_items (cache , use_label_description )
76
+ if not cache then
77
+ return to_completion_items (MiniSnippets .expand ({ match = false , insert = false }), use_label_description )
78
+ end
72
79
73
80
-- Compute cache id
74
81
local _ , context = MiniSnippets .default_prepare ({})
@@ -80,7 +87,7 @@ local function get_completion_items(cache)
80
87
-- Retrieve all raw snippets in context and transform into completion items
81
88
local snippets = MiniSnippets .expand ({ match = false , insert = false })
82
89
--- @cast snippets table
83
- local items = to_completion_items (vim .deepcopy (snippets ))
90
+ local items = to_completion_items (vim .deepcopy (snippets ), use_label_description )
84
91
cache [id ] = items
85
92
86
93
return items
@@ -90,7 +97,7 @@ function source:get_completions(ctx, callback)
90
97
local cache = self .config .use_items_cache and self .items_cache or nil
91
98
92
99
--- @type blink.cmp.CompletionItem[]
93
- local items = get_completion_items (cache )
100
+ local items = get_completion_items (cache , self . config . use_label_description )
94
101
callback ({
95
102
is_incomplete_forward = false ,
96
103
is_incomplete_backward = false ,
0 commit comments