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

Commit d8eb3ba

Browse files
authored
feat: add customizability of dup option for lsp items (#326)
* feat: add customizability of dup option for lsp items * rename variables
1 parent 1773f0e commit d8eb3ba

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lua/completion/source/lsp.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ local function text_document_completion_list_to_complete_items(result, params)
9393

9494
item.word = get_completion_word(completion_item, params.prefix, params.suffix)
9595
item.word = item.word:gsub('\n', ' ')
96+
item.dup = opt.get_option("items_duplicate")['lsp']
9697
item.user_data = {
9798
lsp = {
9899
completion_item = completion_item,

lua/completion/source/snippet.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ M.getUltisnipItems = function(prefix)
1414
end
1515
local priority = vim.g.completion_items_priority['UltiSnips'] or 1
1616
local kind = 'UltiSnips'
17+
local dup = opt.get_option('items_duplicate')[kind] or 1
1718
kind = opt.get_option('customize_lsp_label')[kind] or kind
1819
for key, val in pairs(snippetsList) do
1920
local item = {}
2021
item.word = key
2122
item.kind = kind
2223
item.priority = priority
24+
item.dup = dup
2325
local user_data = {snippet_source = 'UltiSnips', hover = val}
2426
item.user_data = user_data
2527
match.matching(complete_items, prefix, item)
@@ -36,6 +38,7 @@ M.getNeosnippetItems = function(prefix)
3638
end
3739
local kind = 'Neosnippet'
3840
kind = opt.get_option('customize_lsp_label')[kind] or kind
41+
local dup = opt.get_option('items_duplicate')[kind] or 1
3942
local priority = vim.g.completion_items_priority['Neosnippet']
4043
for key, val in pairs(snippetsList) do
4144
local description
@@ -45,6 +48,7 @@ M.getNeosnippetItems = function(prefix)
4548
item.word = key
4649
item.kind = kind
4750
item.priority = priority
51+
item.dup = dup
4852
item.user_data = user_data
4953
match.matching(complete_items, prefix, item)
5054
end
@@ -61,6 +65,7 @@ M.getVsnipItems = function(prefix)
6165
local kind = 'vim-vsnip'
6266
kind = opt.get_option('customize_lsp_label')[kind] or kind
6367
local priority = vim.g.completion_items_priority['vim-vsnip']
68+
local dup = opt.get_option('items_duplicate')[kind] or 1
6469
for _, source in pairs(snippetsList) do
6570
for _, snippet in pairs(source) do
6671
for _, word in pairs(snippet.prefix) do
@@ -69,6 +74,7 @@ M.getVsnipItems = function(prefix)
6974
item.word = word
7075
item.kind = kind
7176
item.menu = snippet.label
77+
item.dup = dup
7278
item.priority = priority
7379
item.user_data = user_data
7480
match.matching(complete_items, prefix, item)
@@ -90,6 +96,7 @@ M.getSnippetsNvimItems = function(prefix)
9096
end
9197
local priority = vim.g.completion_items_priority['snippets.nvim'] or 1
9298
local kind = 'snippets.nvim'
99+
local dup = opt.get_option('items_duplicate')[kind] or 1
93100
kind = opt.get_option('customize_lsp_label')[kind] or kind
94101
for short, long in pairs(snippetsList) do
95102
-- TODO: We cannot put the parsed snippet itself in userdata, since it may
@@ -99,6 +106,7 @@ M.getSnippetsNvimItems = function(prefix)
99106
local item = {}
100107
item.word = short
101108
item.kind = kind
109+
item.dup = dup
102110
-- TODO: Turn actual snippet text into label/description?
103111
item.menu = short
104112
item.priority = priority

plugin/completion.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ if ! exists('g:completion_menu_length')
125125
let g:completion_menu_length = 0
126126
endif
127127

128+
if ! exists('g:completion_items_duplicate')
129+
let g:completion_items_duplicate = {}
130+
endif
131+
128132
inoremap <silent> <Plug>(completion_confirm_completion)
129133
\ <cmd>call completion#wrap_completion()<CR>
130134
@@ -149,3 +153,5 @@ let &cpo = s:save_cpo
149153
unlet s:save_cpo
150154

151155
let g:loaded_completion = 1
156+
157+

0 commit comments

Comments
 (0)