@@ -25,35 +25,28 @@ local function get_completion_word(item)
25
25
return item .label
26
26
end
27
27
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
-
35
28
function M .sort_completion_items (items )
36
29
table.sort (items , function (a , b )
37
30
if a .priority ~= b .priority and a .priority ~= nil and b .priority ~= nil then
38
31
return a .priority > b .priority
39
- elseif vim .g .completion_sorting == ' alphabet' then
40
- return a .word < b .word
41
32
elseif a .score ~= b .score and a .score ~= nil and b .score ~= nil then
42
33
return a .score < b .score
34
+ elseif vim .g .completion_sorting == ' alphabet' then
35
+ return a .word < b .word
43
36
else
44
37
return string.len (a .word ) < string.len (b .word )
45
38
end
46
39
end )
47
40
end
48
41
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 )
50
43
local items = vim .lsp .util .extract_completion_items (result )
51
44
if vim .tbl_isempty (items ) then
52
45
return {}
53
46
end
54
47
55
48
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)
57
50
-- sort_completion_items(items)
58
51
59
52
local matches = {}
@@ -82,18 +75,39 @@ function M.text_document_completion_list_to_complete_items(result, prefix)
82
75
}
83
76
local kind = protocol .CompletionItemKind [completion_item .kind ]
84
77
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
97
111
end
98
112
end
99
113
0 commit comments