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 16
16
-- completion items --
17
17
---- --------------------
18
18
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
26
21
return a .word < b .word
27
22
elseif opt .get_option (" sorting" ) == ' length_desc' then
28
23
return string.len (a .word ) > string.len (b .word )
29
24
else
30
25
return string.len (a .word ) < string.len (b .word )
31
26
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
32
42
end )
33
43
end
34
44
You can’t perform that action at this time.
0 commit comments