Fix entry:get_word()'s cache condition
This commit is contained in:
@@ -98,9 +98,10 @@ entry.get_offset = function(self)
|
||||
end
|
||||
|
||||
---Create word for vim.CompletedItem
|
||||
---NOTE: This method doesn't clear the cache after completionItem/resolve.
|
||||
---@return string
|
||||
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.
|
||||
if misc.safe(self:get_completion_item().word) then
|
||||
return self:get_completion_item().word
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
local spec = require('cmp.utils.spec')
|
||||
local source = require('cmp.source')
|
||||
local async = require('cmp.utils.async')
|
||||
|
||||
local entry = require('cmp.entry')
|
||||
|
||||
@@ -289,11 +291,7 @@ describe('entry', function()
|
||||
end)
|
||||
|
||||
it('[ansiblels] 1', function()
|
||||
local state = spec.state('\t\t', 1, 4)
|
||||
|
||||
-- press g
|
||||
state.input('s')
|
||||
local e = entry.new(state.manual(), state.source(), {
|
||||
local item = {
|
||||
detail = 'ansible.builtin',
|
||||
filterText = 'blockinfile ansible.builtin.blockinfile',
|
||||
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')
|
||||
end)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user