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

Commit 9ed834b

Browse files
committed
rework: allow multiple snippets
doc: update document
1 parent 76f57f0 commit 9ed834b

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

doc/completion-nvim.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ g:completion_chain_complete_list *g:completion_chain_complete_list*
239239
"lsp": lsp completion
240240
"snippet": snippet sources based on g:completion_enable_snippet
241241
"path": path completion relative to the current file.
242+
"UltiSnips": ultisnips source
243+
"Neosnippet": neosnippet source
244+
"vim-vsnip": vim-vsnip source
242245
<
243246

244247
For ins-complete sources, possible 'mode' to the actual key in vim are

lua/completion/source.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ local complete_items_map = {
2424
trigger = path.triggerFunction,
2525
trigger_character = {'/'}
2626
},
27+
['UltiSnips'] = {
28+
item = snippet.getUltisnipItems
29+
},
30+
['vim-vsnip'] = {
31+
item = snippet.getVsnipItems
32+
},
33+
['Neosnippet'] = {
34+
item = snippet.getNeosnippetItems
35+
}
2736
}
2837

2938
M.prefixLength = 0

lua/completion/source/snippet.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local match = require'completion.matching'
44
local M = {}
55

66

7-
local getUltisnipItems = function(prefix)
7+
M.getUltisnipItems = function(prefix)
88
if vim.fn.exists("*UltiSnips#SnippetsInCurrentScope") == 0 then return {} end
99
local snippetsList = api.nvim_call_function('UltiSnips#SnippetsInCurrentScope', {})
1010
local complete_items = {}
@@ -28,7 +28,7 @@ local getUltisnipItems = function(prefix)
2828
return complete_items
2929
end
3030

31-
local getNeosnippetItems = function(prefix)
31+
M.getNeosnippetItems = function(prefix)
3232
if vim.fn.exists("*neosnippet#helpers#get_completion_snippets") == 0 then return {} end
3333
local snippetsList = api.nvim_call_function('neosnippet#helpers#get_completion_snippets', {})
3434
local complete_items = {}
@@ -51,7 +51,7 @@ local getNeosnippetItems = function(prefix)
5151
return complete_items
5252
end
5353

54-
local getVsnipItems = function(prefix)
54+
M.getVsnipItems = function(prefix)
5555
if vim.fn.exists('g:loaded_vsnip') == 0 then return {} end
5656
local snippetsList = api.nvim_call_function('vsnip#source#find', {api.nvim_buf_get_option(0, 'filetype')})
5757
local complete_items = {}
@@ -76,15 +76,15 @@ local getVsnipItems = function(prefix)
7676
return complete_items
7777
end
7878

79-
M.getCompletionItems = function(prefix, score_func, _)
79+
M.getCompletionItems = function(prefix)
8080
local source = vim.g.completion_enable_snippet
8181
local snippet_list = {}
8282
if source == 'UltiSnips' then
83-
snippet_list = getUltisnipItems(prefix, score_func)
83+
snippet_list = M.getUltisnipItems(prefix)
8484
elseif source == 'Neosnippet' then
85-
snippet_list = getNeosnippetItems(prefix, score_func)
85+
snippet_list = M.getNeosnippetItems(prefix)
8686
elseif source == 'vim-vsnip' then
87-
snippet_list = getVsnipItems(prefix, score_func)
87+
snippet_list = M.getVsnipItems(prefix)
8888
end
8989
return snippet_list
9090
end

0 commit comments

Comments
 (0)