Optimize performance

This commit is contained in:
hrsh7th
2022-09-25 21:24:08 +09:00
parent 17a55b3d54
commit e1f31778a8
4 changed files with 13 additions and 11 deletions

View File

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

View File

@@ -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
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
offset = idx
break
return idx
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 ''

View File

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

View File

@@ -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<string, any>
---@field public buffer_opt table<string, any>
---@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