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

Commit bd1cca8

Browse files
committed
Add Snippets support for vim-vsnip.
1 parent 704f9a3 commit bd1cca8

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ supported.
1111
- Asynchronous completion using the `libuv` api.
1212
- Automatically open hover windows when popupmenu is available.
1313
- Automatically open signature help if it's available.
14-
- Snippets integration with UltiSnips and Neosnippet.
14+
- Snippets integration with UltiSnips and Neosnippet and Vsnip.
1515
- Apply *additionalTextEdits* in LSP spec if it's available.
1616
- Chain completion support inspired by ![vim-mucomplete](https://github.com/lifepillar/vim-mucomplete)
1717

@@ -101,10 +101,10 @@ inoremap <silent><expr> <TAB>
101101
- By default other snippets source support are disabled, turn them on by
102102

103103
```vim
104-
" possible value: 'UltiSnips', 'Neosnippet'
104+
" possible value: 'UltiSnips', 'Neosnippet', 'Vsnip'
105105
let g:completion_enable_snippet = 'UltiSnips'
106106
```
107-
- Support `UltiSnips` and `Neosnippet`
107+
- Support `UltiSnips` and `Neosnippet` and `Vsnip`
108108

109109
### LSP Based Snippet parsing
110110

doc/completion-nvim.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ FEATURE *completion-features*
2424
- Asynchronous completion using libuv api.
2525
- Automatically open hover windows when popupmenu is available.
2626
- Automatically open signature help if it's available.
27-
- Snippets integration with UltiSnips and Neosnippet.
27+
- Snippets integration with UltiSnips and Neosnippet and Vsnip.
2828
- ins-complete method integration
2929
- Apply additionalTextEdits in LSP spec if it's available.
3030
- Chain completion support inspired by vim-mucomplete
@@ -87,7 +87,7 @@ g:completion_enable_auto_popup *g:completion_enable_auto_popup*
8787
g:completion_enable_snippet *g:completion_enable_snippet*
8888

8989
You can specify which snippet engines you want to use. Possible values
90-
are |UltiSnips| and |Neosnippet|.
90+
are |UltiSnips| and |Neosnippet| and |Vsnip|.
9191

9292
Note: Snippet engines will not work without setting this variables.
9393

lua/completion.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ function M.confirmCompletion()
7676
api.nvim_call_function('UltiSnips#ExpandSnippet', {})
7777
elseif complete_item.kind == 'Neosnippet' then
7878
api.nvim_input("<c-r>".."=neosnippet#expand('"..complete_item.word.."')".."<CR>")
79+
elseif complete_item.kind == 'Vsnip' then
80+
api.nvim_call_function('vsnip#expand', {})
7981
end
8082
M.completionConfirm = false
8183
end

lua/completion/health.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ local checkSnippetSource = function()
2929
else
3030
health_error("Neosnippet is not available! Check if you install Neosnippet correctly.")
3131
end
32+
elseif snippet_source == 'Vsnip' then
33+
if string.match(api.nvim_get_option("rtp"), ".*vsnip.*") then
34+
health_ok("You are using Vsnip as your snippet source")
35+
else
36+
health_error("Vsnip is not available! Check if you install Vsnip correctly.")
37+
end
3238
else
33-
health_error("You're snippet source is not available! possible value are: UltiSnips, Neosnippet")
39+
health_error("You're snippet source is not available! possible value are: UltiSnips, Neosnippet, Vsnip")
3440
end
3541
end
3642

lua/source/snippet.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,39 @@ local getNeosnippetItems = function(prefix)
5151
return complete_items
5252
end
5353

54+
local getVsnipItems = function(prefix)
55+
if vim.fn.exists("*vsnip#source#find") == 0 then return {} end
56+
local snippetsList = api.nvim_call_function('vsnip#source#find', {api.nvim_buf_get_option(0, 'filetype')})
57+
local complete_items = {}
58+
if vim.tbl_isempty(snippetsList) == 0 then
59+
return {}
60+
end
61+
local priority = vim.g.completion_items_priority['Vsnip']
62+
for sourceIdx, source in pairs(snippetsList) do
63+
for snippetIdx, snippet in pairs(source) do
64+
for prefixIdx, word in pairs(snippet.prefix) do
65+
local user_data = {hover = snippet.description}
66+
local item = {}
67+
item.word = word
68+
item.kind = 'Vsnip'
69+
item.priority = priority
70+
item.user_data = user_data
71+
match.matching(complete_items, prefix, item)
72+
end
73+
end
74+
end
75+
return complete_items
76+
end
77+
5478
M.getCompletionItems = function(prefix, score_func, _)
5579
local source = vim.g.completion_enable_snippet
5680
local snippet_list = {}
5781
if source == 'UltiSnips' then
5882
snippet_list = getUltisnipItems(prefix, score_func)
5983
elseif source == 'Neosnippet' then
6084
snippet_list = getNeosnippetItems(prefix, score_func)
85+
elseif source == 'Vsnip' then
86+
snippet_list = getVsnipItems(prefix, source_func)
6187
end
6288
return snippet_list
6389
end

0 commit comments

Comments
 (0)