From 076c54a39c44147a87102cf3b6ac4743800330bb Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 15 May 2023 18:15:09 +0200 Subject: [PATCH] perf(source): cache filtered entries for current context --- lua/cmp/source.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/cmp/source.lua b/lua/cmp/source.lua index 032536e64..a62f3a21f 100644 --- a/lua/cmp/source.lua +++ b/lua/cmp/source.lua @@ -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 @@ -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 @@ -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 = {} @@ -116,6 +122,7 @@ source.get_entries = function(self, ctx) end end end + self.filtered = { entries = entries, ctx = ctx } return entries end