Change configuration schema
This commit is contained in:
@@ -42,25 +42,15 @@ return function()
|
||||
},
|
||||
|
||||
sorting = {
|
||||
sort = function(entries)
|
||||
table.sort(entries, function(entry1, entry2)
|
||||
for _, fn in ipairs({
|
||||
compare.offset,
|
||||
compare.exact,
|
||||
compare.score,
|
||||
compare.kind,
|
||||
compare.sort_text,
|
||||
compare.length,
|
||||
compare.order,
|
||||
}) do
|
||||
local diff = fn(entry1, entry2)
|
||||
if diff ~= nil then
|
||||
return diff
|
||||
end
|
||||
end
|
||||
end)
|
||||
return entries
|
||||
end
|
||||
comparators = {
|
||||
compare.offset,
|
||||
compare.exact,
|
||||
compare.score,
|
||||
compare.kind,
|
||||
compare.sort_text,
|
||||
compare.length,
|
||||
compare.order,
|
||||
}
|
||||
},
|
||||
|
||||
formatting = {
|
||||
|
||||
@@ -105,7 +105,14 @@ menu.update = function(self, ctx, sources)
|
||||
end
|
||||
|
||||
-- sort.
|
||||
config.get().sorting.sort(entries)
|
||||
table.sort(entries, function(e1, e2)
|
||||
for _, fn in ipairs(config.get().sorting.comparators) do
|
||||
local diff = fn(e1, e2)
|
||||
if diff ~= nil then
|
||||
return diff
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- create vim items.
|
||||
local items = {}
|
||||
|
||||
@@ -69,7 +69,7 @@ cmp.TriggerEvent.TextChanged = 'TextChanged'
|
||||
---@field select boolean
|
||||
|
||||
---@class cmp.SortingConfig
|
||||
---@field public sort fun(entries: cmp.Entry[]): cmp.Entry[]
|
||||
---@field public comparators function[]
|
||||
|
||||
---@class cmp.FormattingConfig
|
||||
---@field public format fun(entry: cmp.Entry, suggeset_offset: number): vim.CompletedItem
|
||||
|
||||
Reference in New Issue
Block a user