diff --git a/README.md b/README.md index 67fa9a6..46f9059 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ supported. - Asynchronous completion using the `libuv` api. - Automatically open hover windows when popupmenu is available. - Automatically open signature help if it's available. -- Snippets integration with UltiSnips and Neosnippet. +- Snippets integration with UltiSnips and Neosnippet and vim-vsnip. - Apply *additionalTextEdits* in LSP spec if it's available. - Chain completion support inspired by ![vim-mucomplete](https://github.com/lifepillar/vim-mucomplete) @@ -101,10 +101,10 @@ inoremap - By default other snippets source support are disabled, turn them on by ```vim -" possible value: 'UltiSnips', 'Neosnippet' +" possible value: 'UltiSnips', 'Neosnippet', 'vim-vsnip' let g:completion_enable_snippet = 'UltiSnips' ``` -- Support `UltiSnips` and `Neosnippet` +- Support `UltiSnips` and `Neosnippet` and `vim-vsnip` ### LSP Based Snippet parsing diff --git a/doc/completion-nvim.txt b/doc/completion-nvim.txt index 448a2cf..7db2b81 100644 --- a/doc/completion-nvim.txt +++ b/doc/completion-nvim.txt @@ -24,7 +24,7 @@ FEATURE *completion-features* - Asynchronous completion using libuv api. - Automatically open hover windows when popupmenu is available. - Automatically open signature help if it's available. -- Snippets integration with UltiSnips and Neosnippet. +- Snippets integration with UltiSnips and Neosnippet and vim-vsnip. - ins-complete method integration - Apply additionalTextEdits in LSP spec if it's available. - Chain completion support inspired by vim-mucomplete @@ -87,7 +87,7 @@ g:completion_enable_auto_popup *g:completion_enable_auto_popup* g:completion_enable_snippet *g:completion_enable_snippet* You can specify which snippet engines you want to use. Possible values - are |UltiSnips| and |Neosnippet|. + are |UltiSnips| and |Neosnippet| and |vim-vsnip|. Note: Snippet engines will not work without setting this variables. diff --git a/lua/completion.lua b/lua/completion.lua index cf3dd11..9b2f438 100644 --- a/lua/completion.lua +++ b/lua/completion.lua @@ -76,6 +76,8 @@ function M.confirmCompletion() api.nvim_call_function('UltiSnips#ExpandSnippet', {}) elseif complete_item.kind == 'Neosnippet' then api.nvim_input("".."=neosnippet#expand('"..complete_item.word.."')".."") + elseif complete_item.kind == 'vim-vsnip' then + api.nvim_call_function('vsnip#expand', {}) end M.completionConfirm = false end diff --git a/lua/completion/health.lua b/lua/completion/health.lua index de79755..fe6c9d4 100644 --- a/lua/completion/health.lua +++ b/lua/completion/health.lua @@ -29,8 +29,14 @@ local checkSnippetSource = function() else health_error("Neosnippet is not available! Check if you install Neosnippet correctly.") end + elseif snippet_source == 'vim-vsnip' then + if string.match(api.nvim_get_option("rtp"), ".*vsnip.*") then + health_ok("You are using vim-vsnip as your snippet source") + else + health_error("vim-vsnip is not available! Check if you install vim-vsnip correctly.") + end else - health_error("You're snippet source is not available! possible value are: UltiSnips, Neosnippet") + health_error("You're snippet source is not available! possible value are: UltiSnips, Neosnippet, vim-vsnip") end end diff --git a/lua/source/snippet.lua b/lua/source/snippet.lua index 4d65c21..3e050ef 100644 --- a/lua/source/snippet.lua +++ b/lua/source/snippet.lua @@ -51,6 +51,31 @@ local getNeosnippetItems = function(prefix) return complete_items end +local getVsnipItems = function(prefix) + if vim.fn.exists('g:loaded_vsnip') == 0 then return {} end + local snippetsList = api.nvim_call_function('vsnip#source#find', {api.nvim_buf_get_option(0, 'filetype')}) + local complete_items = {} + if vim.tbl_isempty(snippetsList) == 0 then + return {} + end + local priority = vim.g.completion_items_priority['vim-vsnip'] + for _, source in pairs(snippetsList) do + for _, snippet in pairs(source) do + for _, word in pairs(snippet.prefix) do + local user_data = {hover = snippet.description} + local item = {} + item.word = word + item.kind = 'vim-vsnip' + item.menu = snippet.label + item.priority = priority + item.user_data = user_data + match.matching(complete_items, prefix, item) + end + end + end + return complete_items +end + M.getCompletionItems = function(prefix, score_func, _) local source = vim.g.completion_enable_snippet local snippet_list = {} @@ -58,6 +83,8 @@ M.getCompletionItems = function(prefix, score_func, _) snippet_list = getUltisnipItems(prefix, score_func) elseif source == 'Neosnippet' then snippet_list = getNeosnippetItems(prefix, score_func) + elseif source == 'vim-vsnip' then + snippet_list = getVsnipItems(prefix, score_func) end return snippet_list end