forked from nvim-lua/completion-nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnippet.lua
More file actions
92 lines (86 loc) · 2.78 KB
/
snippet.lua
File metadata and controls
92 lines (86 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
local vim = vim
local api = vim.api
local match = require'completion.matching'
local M = {}
local getUltisnipItems = function(prefix)
if vim.fn.exists("*UltiSnips#SnippetsInCurrentScope") == 0 then return {} end
local snippetsList = api.nvim_call_function('UltiSnips#SnippetsInCurrentScope', {})
local complete_items = {}
if vim.tbl_isempty(snippetsList) then
return {}
end
local priority = vim.g.completion_items_priority['UltiSnips'] or 1
for key, val in pairs(snippetsList) do
-- fix lua parsing issue
if key == true then
key = 'true'
end
local item = {}
item.word = key
item.kind = 'UltiSnips'
item.priority = priority
local user_data = {hover = val}
item.user_data = user_data
match.matching(complete_items, prefix, item)
end
return complete_items
end
local getNeosnippetItems = function(prefix)
if vim.fn.exists("*neosnippet#helpers#get_completion_snippets") == 0 then return {} end
local snippetsList = api.nvim_call_function('neosnippet#helpers#get_completion_snippets', {})
local complete_items = {}
if vim.tbl_isempty(snippetsList) == 0 then
return {}
end
local priority = vim.g.completion_items_priority['Neosnippet']
for key, val in pairs(snippetsList) do
if key == true then
key = 'true'
end
local user_data = {hover = val.description}
local item = {}
item.word = key
item.kind = 'Neosnippet'
item.priority = priority
item.user_data = user_data
match.matching(complete_items, prefix, item)
end
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 = {}
if source == 'UltiSnips' then
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
return M