restore max_item_count

This commit is contained in:
hrsh7th
2023-06-09 21:26:42 +09:00
parent 6f118169af
commit 559b688cda
3 changed files with 17 additions and 4 deletions

View File

@@ -57,7 +57,8 @@ source.reset = function(self)
self.request_offset = -1
self.completion_context = nil
self.status = source.SourceStatus.WAITING
self.complete_dedup(function() end)
self.complete_dedup(function()
end)
end
---Return source config
@@ -92,9 +93,6 @@ source.get_entries = function(self, ctx)
local prev = self.cache:get({ 'get_entries', tostring(self.revision) })
if prev and ctx.cursor.row == prev.ctx.cursor.row and self.offset == prev.offset then
if ctx.cursor.col == prev.ctx.cursor.col then
return prev.entries
end
-- only use prev entries when cursor is moved forward.
-- and the pattern offset is the same.
if prev.ctx.cursor.col <= ctx.cursor.col then
@@ -133,6 +131,14 @@ source.get_entries = function(self, ctx)
self.cache:set({ 'get_entries', tostring(self.revision) }, { entries = entries, ctx = ctx, offset = self.offset })
if self:get_source_config().max_item_count then
local limited_entries = {}
for i = 1, math.min(#entries, self:get_source_config().max_item_count) do
limited_entries[i] = entries[i]
end
entries = limited_entries
end
return entries
end

View File

@@ -162,6 +162,7 @@ cmp.ItemField = {
---@field public trigger_characters string[]|nil
---@field public keyword_pattern string|nil
---@field public keyword_length integer|nil
---@field public max_item_count integer|nil
---@field public group_index integer|nil
---@field public entry_filter nil|function(entry: cmp.Entry, ctx: cmp.Context): boolean