diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 423420d..89aadd2 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -58,6 +58,7 @@ end core.get_context = function(self, option) local prev = self.context:clone() prev.prev_context = nil + prev.cache = nil local ctx = context.new(prev, option) self:set_context(ctx) return self.context diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua index 6fa5460..34cdf2c 100644 --- a/lua/cmp/entry.lua +++ b/lua/cmp/entry.lua @@ -60,13 +60,15 @@ entry.get_offset = function(self) local range = misc.safe(self:get_completion_item().textEdit.insert) or misc.safe(self:get_completion_item().textEdit.range) if range then - local c = misc.to_vimindex(self.context.cursor_line, range.start.character) - for idx = c, self.source_offset do - if not char.is_white(string.byte(self.context.cursor_line, idx)) then - offset = idx - break + offset = self.context.cache:ensure({ 'entry', 'get_offset', range.start.character }, function() + local c = misc.to_vimindex(self.context.cursor_line, range.start.character) + for idx = c, self.source_offset do + if not char.is_white(string.byte(self.context.cursor_line, idx)) then + return idx + end end - end + return offset + end) end else -- NOTE @@ -213,7 +215,8 @@ entry.get_view = function(self, suggest_offset, entries_buf) view.kind.text = item.kind or '' view.kind.bytes = #view.kind.text view.kind.width = vim.fn.strdisplaywidth(view.kind.text) - view.kind.hl_group = item.kind_hl_group or ('CmpItemKind' .. (types.lsp.CompletionItemKind[self:get_kind()] or '') + view.kind.hl_group = item.kind_hl_group or + ('CmpItemKind' .. (types.lsp.CompletionItemKind[self:get_kind()] or '') ) view.menu = {} view.menu.text = item.menu or '' diff --git a/lua/cmp/source.lua b/lua/cmp/source.lua index 9a364ec..f3d2047 100644 --- a/lua/cmp/source.lua +++ b/lua/cmp/source.lua @@ -105,13 +105,14 @@ source.get_entries = function(self, ctx) local inputs = {} local entries = {} + local matching_config = self:get_matching_config() for _, e in ipairs(target_entries) do local o = e:get_offset() if not inputs[o] then inputs[o] = string.sub(ctx.cursor_before_line, o) end - local match = e:match(inputs[o], self:get_matching_config()) + local match = e:match(inputs[o], matching_config) e.score = match.score e.exact = false if e.score >= 1 then diff --git a/lua/cmp/utils/window.lua b/lua/cmp/utils/window.lua index b150c03..837dc6d 100644 --- a/lua/cmp/utils/window.lua +++ b/lua/cmp/utils/window.lua @@ -1,4 +1,3 @@ -local cache = require('cmp.utils.cache') local misc = require('cmp.utils.misc') local buffer = require('cmp.utils.buffer') local api = require('cmp.utils.api') @@ -20,7 +19,6 @@ local api = require('cmp.utils.api') ---@field public style cmp.WindowStyle ---@field public opt table ---@field public buffer_opt table ----@field public cache cmp.Cache local window = {} ---new @@ -32,7 +30,6 @@ window.new = function() self.sbar_win = nil self.thumb_win = nil self.style = {} - self.cache = cache.new() self.opt = {} self.buffer_opt = {} return self