Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 Vsnip.
- Apply *additionalTextEdits* in LSP spec if it's available.
- Chain completion support inspired by ![vim-mucomplete](https://github.com/lifepillar/vim-mucomplete)

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

```vim
" possible value: 'UltiSnips', 'Neosnippet'
" possible value: 'UltiSnips', 'Neosnippet', 'Vsnip'
let g:completion_enable_snippet = 'UltiSnips'
```
- Support `UltiSnips` and `Neosnippet`
- Support `UltiSnips` and `Neosnippet` and `Vsnip`

### LSP Based Snippet parsing

Expand Down
4 changes: 2 additions & 2 deletions doc/completion-nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 Vsnip.
- ins-complete method integration
- Apply additionalTextEdits in LSP spec if it's available.
- Chain completion support inspired by vim-mucomplete
Expand Down Expand Up @@ -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 |Vsnip|.

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

Expand Down
2 changes: 2 additions & 0 deletions lua/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ function M.confirmCompletion()
api.nvim_call_function('UltiSnips#ExpandSnippet', {})
elseif complete_item.kind == 'Neosnippet' then
api.nvim_input("<c-r>".."=neosnippet#expand('"..complete_item.word.."')".."<CR>")
elseif complete_item.kind == 'Vsnip' then
api.nvim_call_function('vsnip#expand', {})
end
M.completionConfirm = false
end
Expand Down
8 changes: 7 additions & 1 deletion lua/completion/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ local checkSnippetSource = function()
else
health_error("Neosnippet is not available! Check if you install Neosnippet correctly.")
end
elseif snippet_source == 'Vsnip' then
if string.match(api.nvim_get_option("rtp"), ".*vsnip.*") then
health_ok("You are using Vsnip as your snippet source")
else
health_error("Vsnip is not available! Check if you install 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, Vsnip")
end
end

Expand Down
26 changes: 26 additions & 0 deletions lua/source/snippet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,39 @@ local getNeosnippetItems = function(prefix)
return complete_items
end

local getVsnipItems = function(prefix)
if vim.fn.exists("*vsnip#source#find") == 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['Vsnip']
for sourceIdx, source in pairs(snippetsList) do
for snippetIdx, snippet in pairs(source) do
for prefixIdx, word in pairs(snippet.prefix) do
local user_data = {hover = snippet.description}
local item = {}
item.word = word
item.kind = 'Vsnip'
item.priority = priority
item.user_data = user_data
match.matching(complete_items, prefix, item)
end
Copy link
Contributor

@hrsh7th hrsh7th May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your work still needed but complete_items creation is bundled in vim-vsnip side now so we can use vsnip#get_complete_items(bufnr) instead of this codes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I personally thinks the current solution is better because it respect the priority and and score from fuzzy matching(it'll affect the order in the popup menu).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will follow your opinion.

I recommend using prefix[0] instead of for prefixIdx, word in pairs(snippet.prefix) do.

end
end
return complete_items
end

M.getCompletionItems = function(prefix, score_func, _)
local source = vim.g.completion_enable_snippet
local snippet_list = {}
if source == 'UltiSnips' then
snippet_list = getUltisnipItems(prefix, score_func)
elseif source == 'Neosnippet' then
snippet_list = getNeosnippetItems(prefix, score_func)
elseif source == 'Vsnip' then
snippet_list = getVsnipItems(prefix, source_func)
end
return snippet_list
end
Expand Down