This repository was archived by the owner on Oct 13, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change 1616-- completion items --
1717---- --------------------
1818
19- function M .sort_completion_items (items )
20- table.sort (items , function (a , b )
21- if a .priority ~= b .priority and a .priority ~= nil and b .priority ~= nil then
22- return a .priority > b .priority
23- elseif a .score ~= b .score and a .score ~= nil and b .score ~= nil then
24- return a .score < b .score
25- elseif opt .get_option (" sorting" ) == ' alphabet' then
19+ local function compare_strings (a , b )
20+ if opt .get_option (" sorting" ) == ' alphabet' then
2621 return a .word < b .word
2722 elseif opt .get_option (" sorting" ) == ' length_desc' then
2823 return string.len (a .word ) > string.len (b .word )
2924 else
3025 return string.len (a .word ) < string.len (b .word )
3126 end
27+ end
28+
29+ local function compare_scores_then_strings (a , b )
30+ if a .score == b .score or a .score == nil or b .score == nil then
31+ return compare_strings (a , b );
32+ end
33+ return a .score < b .score
34+ end
35+
36+ function M .sort_completion_items (items )
37+ table.sort (items , function (a , b )
38+ if a .priority == b .priority or a .priority == nil or b .priority == nil then
39+ return compare_scores_then_strings (a , b )
40+ end
41+ return a .priority > b .priority
3242 end )
3343end
3444
You can’t perform that action at this time.
0 commit comments