From b43bfaf3229d6b39d8baaa567b13c6be0623bf12 Mon Sep 17 00:00:00 2001 From: hrsh7th <629908+hrsh7th@users.noreply.github.com> Date: Sun, 28 May 2023 22:47:11 +0900 Subject: [PATCH] fix(entry): fix matches highlight information fixes #1426 --- lua/cmp/entry.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua index 05f8a83..50b6535 100644 --- a/lua/cmp/entry.lua +++ b/lua/cmp/entry.lua @@ -383,11 +383,12 @@ entry.match = function(self, input, matching_config) score, matches = matcher.match(input, filter_text, option) -- Support the language server that doesn't respect VSCode's behaviors. + local prefix = '' if score == 0 then if self:get_completion_item().textEdit and not misc.empty(self:get_completion_item().textEdit.newText) then local diff = self.source_offset - self:get_offset() if diff > 0 then - local prefix = string.sub(self.context.cursor_line, self:get_offset(), self:get_offset() + diff) + prefix = string.sub(self.context.cursor_line, self:get_offset(), self:get_offset() + diff) local accept = nil accept = accept or string.match(prefix, '^[^%a]+$') accept = accept or string.find(self:get_completion_item().textEdit.newText, prefix, 1, true) @@ -402,11 +403,13 @@ entry.match = function(self, input, matching_config) end end - if score ~= 0 then - local vim_item = self:get_vim_item(self:get_offset()) + -- Fix highlight if filterText is not the same to vim_item.abbr. + if score > 0 then + local vim_item = self:get_vim_item(self.source_offset) filter_text = vim_item.abbr or vim_item.word if not checked[filter_text] then - _, matches = matcher.match(input, filter_text, option) + local diff = self.source_offset - self:get_offset() + _, matches = matcher.match(input:sub(1 + diff), filter_text, option) end end