Skip to content

Commit

Permalink
perf(source): cache filtered entries for current context
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 15, 2023
1 parent b55b269 commit 076c54a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lua/cmp/source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local char = require('cmp.utils.char')
---@field public incomplete boolean
---@field public is_triggered_by_symbol boolean
---@field public entries cmp.Entry[]
---@field public filtered {entries: cmp.Entry[], ctx: cmp.Context}
---@field public offset integer
---@field public request_offset integer
---@field public context cmp.Context
Expand Down Expand Up @@ -53,6 +54,7 @@ source.reset = function(self)
self.is_triggered_by_symbol = false
self.incomplete = false
self.entries = {}
self.filtered = {}
self.offset = -1
self.request_offset = -1
self.completion_context = nil
Expand Down Expand Up @@ -88,6 +90,10 @@ source.get_entries = function(self, ctx)
return {}
end

if self.filtered.ctx and self.filtered.ctx.id == ctx.id then
return self.filtered.entries
end

local entry_filter = self:get_entry_filter()

local inputs = {}
Expand Down Expand Up @@ -116,6 +122,7 @@ source.get_entries = function(self, ctx)
end
end
end
self.filtered = { entries = entries, ctx = ctx }
return entries
end

Expand Down

0 comments on commit 076c54a

Please sign in to comment.