Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit c7f8d8d

Browse files
authored
Merge pull request #233 from Conni2461/fix_custom_snip_label
Fixes expand when using custom label for snippets
2 parents 3d07c33 + ba0aa6a commit c7f8d8d

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

lua/completion.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ local function hasConfirmedCompletion()
132132
if opt.get_option('enable_auto_paren') == 1 then
133133
autoAddParens(completed_item)
134134
end
135-
if completed_item.kind == 'UltiSnips' then
135+
if completed_item.user_data.snippet_source == 'UltiSnips' then
136136
api.nvim_call_function('UltiSnips#ExpandSnippet', {})
137-
elseif completed_item.kind == 'Neosnippet' then
137+
elseif completed_item.user_data.snippet_source == 'Neosnippet' then
138138
api.nvim_input("<c-r>".."=neosnippet#expand('"..completed_item.word.."')".."<CR>")
139-
elseif completed_item.kind == 'vim-vsnip' then
139+
elseif completed_item.user_data.snippet_source == 'vim-vsnip' then
140140
api.nvim_call_function('vsnip#expand', {})
141-
elseif completed_item.kind == 'snippets.nvim' then
142-
require'snippets'.expand_at_cursor()
141+
elseif completed_item.user_data.snippet_source == 'snippets.nvim' then
142+
require'snippets'.expand_at_cursor()
143143
end
144144
end
145145

@@ -266,4 +266,3 @@ M.on_attach = function(option)
266266
end
267267

268268
return M
269-

lua/completion/source/snippet.lua

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ M.getUltisnipItems = function(prefix)
2424
item.word = key
2525
item.kind = kind
2626
item.priority = priority
27-
local user_data = {hover = val}
27+
local user_data = {snippet_source = 'UltiSnips', hover = val}
2828
item.user_data = user_data
2929
match.matching(complete_items, prefix, item)
3030
end
@@ -45,7 +45,7 @@ M.getNeosnippetItems = function(prefix)
4545
if key == true then
4646
key = 'true'
4747
end
48-
local user_data = {hover = val.description}
48+
local user_data = {snippet_source = 'Neosnippet', hover = val.description}
4949
local item = {}
5050
item.word = key
5151
item.kind = kind
@@ -69,7 +69,7 @@ M.getVsnipItems = function(prefix)
6969
for _, source in pairs(snippetsList) do
7070
for _, snippet in pairs(source) do
7171
for _, word in pairs(snippet.prefix) do
72-
local user_data = {hover = snippet.description}
72+
local user_data = {snippet_source = 'vim-vsnip', hover = snippet.description}
7373
local item = {}
7474
item.word = word
7575
item.kind = kind
@@ -95,19 +95,20 @@ M.getSnippetsNvimItems = function(prefix)
9595
end
9696
local priority = vim.g.completion_items_priority['snippets.nvim'] or 1
9797
local kind = 'snippets.nvim'
98+
kind = opt.get_option('customize_lsp_label')[kind] or kind
9899
for short, long in pairs(snippetsList) do
99-
-- TODO: We cannot put the parsed snippet itself in userdata, since it may
100-
-- contain Lua functions (see
101-
-- https://github.com/norcalli/snippets.nvim#notes-because-this-is-beta-release-software)
102-
local user_data = {}
103-
local item = {}
104-
item.word = short
105-
item.kind = kind
106-
-- TODO: Turn actual snippet text into label/description?
107-
item.menu = short
108-
item.priority = priority
109-
item.user_data = user_data
110-
match.matching(complete_items, prefix, item)
100+
-- TODO: We cannot put the parsed snippet itself in userdata, since it may
101+
-- contain Lua functions (see
102+
-- https://github.com/norcalli/snippets.nvim#notes-because-this-is-beta-release-software)
103+
local user_data = {snippet_source = 'snippets.nvim'}
104+
local item = {}
105+
item.word = short
106+
item.kind = kind
107+
-- TODO: Turn actual snippet text into label/description?
108+
item.menu = short
109+
item.priority = priority
110+
item.user_data = user_data
111+
match.matching(complete_items, prefix, item)
111112
end
112113
return complete_items
113114
end

0 commit comments

Comments
 (0)