Change configuration schema

This commit is contained in:
hrsh7th
2021-08-05 16:21:07 +09:00
parent cf61d0de50
commit 399cee4e24
3 changed files with 18 additions and 21 deletions

View File

@@ -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 = {

View File

@@ -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 = {}

View File

@@ -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