@@ -25,35 +25,28 @@ local function get_completion_word(item)
2525 return item .label
2626end
2727
28- local function remove_unmatch_completion_items (items , prefix )
29- return vim .tbl_filter (function (item )
30- local word = get_completion_word (item )
31- return vim .startswith (word , prefix )
32- end , items )
33- end
34-
3528function M .sort_completion_items (items )
3629 table.sort (items , function (a , b )
3730 if a .priority ~= b .priority and a .priority ~= nil and b .priority ~= nil then
3831 return a .priority > b .priority
39- elseif vim .g .completion_sorting == ' alphabet' then
40- return a .word < b .word
4132 elseif a .score ~= b .score and a .score ~= nil and b .score ~= nil then
4233 return a .score < b .score
34+ elseif vim .g .completion_sorting == ' alphabet' then
35+ return a .word < b .word
4336 else
4437 return string.len (a .word ) < string.len (b .word )
4538 end
4639 end )
4740end
4841
49- function M .text_document_completion_list_to_complete_items (result , prefix )
42+ function M .text_document_completion_list_to_complete_items (result , prefix , score_func )
5043 local items = vim .lsp .util .extract_completion_items (result )
5144 if vim .tbl_isempty (items ) then
5245 return {}
5346 end
5447
5548 local customize_label = vim .g .completion_customize_lsp_label
56- items = remove_unmatch_completion_items (items , prefix )
49+ -- items = remove_unmatch_completion_items(items, prefix)
5750 -- sort_completion_items(items)
5851
5952 local matches = {}
@@ -82,18 +75,39 @@ function M.text_document_completion_list_to_complete_items(result, prefix)
8275 }
8376 local kind = protocol .CompletionItemKind [completion_item .kind ]
8477 local priority = vim .g .completion_items_priority [kind ] or 1
85- table.insert (matches , {
86- word = word ,
87- abbr = completion_item .label ,
88- kind = customize_label [kind ] or kind or ' ' ,
89- menu = completion_item .detail or ' ' ,
90- info = info ,
91- priority = priority ,
92- icase = 1 ,
93- user_data = user_data ,
94- dup = 1 ,
95- empty = 1 ,
96- })
78+ if vim .g .completion_fuzzy_match == 1 then
79+ local score = score_func (prefix , word )
80+ if score <= 1 then
81+ table.insert (matches , {
82+ word = word ,
83+ abbr = completion_item .label ,
84+ kind = customize_label [kind ] or kind or ' ' ,
85+ menu = completion_item .detail or ' ' ,
86+ info = info ,
87+ priority = priority ,
88+ score = score ,
89+ icase = 1 ,
90+ user_data = user_data ,
91+ dup = 1 ,
92+ empty = 1 ,
93+ })
94+ end
95+ else
96+ if vim .startswith (word , prefix ) then
97+ table.insert (matches , {
98+ word = word ,
99+ abbr = completion_item .label ,
100+ kind = customize_label [kind ] or kind or ' ' ,
101+ menu = completion_item .detail or ' ' ,
102+ info = info ,
103+ priority = priority ,
104+ icase = 1 ,
105+ user_data = user_data ,
106+ dup = 1 ,
107+ empty = 1 ,
108+ })
109+ end
110+ end
97111 end
98112 end
99113
0 commit comments