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

Commit 62b5375

Browse files
committed
feat: easier way to setup matcher and sorter
feat: easier way to setup matcher and sorter
1 parent fcfa9d4 commit 62b5375

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lua/completion.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ M.customize_buf_label = function(label)
182182
api.nvim_buf_set_var(0, "completion_buf_customize_lsp_label", label)
183183
end
184184

185-
M.on_attach = function()
185+
M.on_attach = function(opt)
186186
api.nvim_command [[augroup CompletionCommand]]
187187
api.nvim_command("autocmd! * <buffer>")
188188
api.nvim_command("autocmd InsertEnter <buffer> lua require'completion'.on_InsertEnter()")
@@ -195,8 +195,18 @@ M.on_attach = function()
195195
'<cmd>call completion#wrap_completion()<CR>', {silent=true, noremap=true})
196196
end
197197
api.nvim_buf_set_var(0, 'completion_enable', 1)
198+
if opt == nil then return end
199+
local sorter = opt.sorter
200+
local matcher = opt.matcher
201+
if sorter ~= nil then
202+
vim.validate{sorter={sorter, 'string'}}
203+
vim.b.completion_sorting = sorter
204+
end
205+
if matcher ~= nil then
206+
vim.validate{matcher={matcher, 'table'}}
207+
vim.b.completion_matching_strategy_list = matcher
208+
end
198209
end
199210

200211
return M
201212

202-

lua/source/lsp.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ local function text_document_completion_list_to_complete_items(result, prefix)
6363
item.priority = vim.g.completion_items_priority[item.kind] or 1
6464
item.menu = completion_item.detail or ''
6565
local matching_piroity = 1
66-
for _, method in ipairs(vim.g.completion_matching_strategy_list) do
66+
67+
local matcher_list = vim.b.completion_matching_strategy_list or vim.g.completion_matching_strategy_list
68+
for _, method in ipairs(matcher_list) do
6769
local is_match, score = match.matching_strategy[method](prefix, item.word)
6870
item.score = score
6971
if is_match then

0 commit comments

Comments
 (0)