Fix entry:get_word()'s cache condition

This commit is contained in:
hrsh7th
2022-02-15 20:34:21 +09:00
parent 4f5cc6a9c8
commit 13d64460cb
2 changed files with 16 additions and 6 deletions

View File

@@ -98,9 +98,10 @@ entry.get_offset = function(self)
end end
---Create word for vim.CompletedItem ---Create word for vim.CompletedItem
---NOTE: This method doesn't clear the cache after completionItem/resolve.
---@return string ---@return string
entry.get_word = function(self) entry.get_word = function(self)
return self.cache:ensure({ 'get_word', self.resolved_completion_item and 1 or 0 }, function() return self.cache:ensure({ 'get_word' }, function()
--NOTE: This is nvim-cmp specific implementation. --NOTE: This is nvim-cmp specific implementation.
if misc.safe(self:get_completion_item().word) then if misc.safe(self:get_completion_item().word) then
return self:get_completion_item().word return self:get_completion_item().word

View File

@@ -1,4 +1,6 @@
local spec = require('cmp.utils.spec') local spec = require('cmp.utils.spec')
local source = require('cmp.source')
local async = require('cmp.utils.async')
local entry = require('cmp.entry') local entry = require('cmp.entry')
@@ -289,11 +291,7 @@ describe('entry', function()
end) end)
it('[ansiblels] 1', function() it('[ansiblels] 1', function()
local state = spec.state('\t\t', 1, 4) local item = {
-- press g
state.input('s')
local e = entry.new(state.manual(), state.source(), {
detail = 'ansible.builtin', detail = 'ansible.builtin',
filterText = 'blockinfile ansible.builtin.blockinfile', filterText = 'blockinfile ansible.builtin.blockinfile',
kind = 7, kind = 7,
@@ -312,7 +310,18 @@ describe('entry', function()
}, },
}, },
}, },
}
local s = source.new('dummy', {
resolve = function(_, _, callback)
item.textEdit.newText = 'modified'
callback(item)
end,
}) })
local e = entry.new(spec.state('', 1, 1).manual(), s, item)
assert.are.equal(e:get_vim_item(e:get_offset()).word, 'blockinfile')
async.sync(function(done)
e:resolve(done)
end, 100)
assert.are.equal(e:get_vim_item(e:get_offset()).word, 'blockinfile') assert.are.equal(e:get_vim_item(e:get_offset()).word, 'blockinfile')
end) end)