Fix invalid temporary text

This commit is contained in:
hrsh7th
2021-08-27 23:06:35 +09:00
parent 61984efaf0
commit 405581e740
5 changed files with 27 additions and 4 deletions

View File

@@ -109,12 +109,13 @@ entry.get_word = function(self)
end
elseif misc.safe(self.completion_item.insertText) then
word = str.trim(self.completion_item.insertText)
word = str.get_word(word)
if self.completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet then
word = str.get_word(word)
end
else
word = str.trim(self.completion_item.label)
word = str.get_word(word, '')
end
return word
return str.oneline(word)
end)
end

View File

@@ -275,7 +275,7 @@ describe('entry', function()
insertTextFormat = 1,
insertText = '__init__(self) -> None:\n pass',
})
assert.are.equal(e:get_vim_item(e:get_offset()).word, '__init__')
assert.are.equal(e:get_vim_item(e:get_offset()).word, '__init__(self) -> None:')
assert.are.equal(e:get_filter_text(), '__init__')
end)
end)

View File

@@ -1,4 +1,5 @@
local config = require('cmp.config')
local async = require('cmp.utils.async')
local spec = require('cmp.utils.spec')
local source = require('cmp.source')
@@ -85,10 +86,15 @@ describe('source', function()
})
end,
})
vim.wait(100, function() return s.status == source.SourceStatus.COMPLETED end, 100, false)
assert.is.truthy(s:complete(state.input('s'), function() end))
vim.wait(100, function() return s.status == source.SourceStatus.COMPLETED end, 100, false)
assert.is.truthy(s:complete(state.input('p'), function() end))
vim.wait(100, function() return s.status == source.SourceStatus.COMPLETED end, 100, false)
assert.is.truthy(s:complete(state.input('e'), function() end))
vim.wait(100, function() return s.status == source.SourceStatus.COMPLETED end, 100, false)
assert.is.truthy(s:complete(state.input('c'), function() end))
vim.wait(100, function() return s.status == source.SourceStatus.COMPLETED end, 100, false)
end)
end)
end)

View File

@@ -51,5 +51,20 @@ async.dedup = function()
end
end
---Wiat for callback.
---@param runner fun(done: function)
---@param timeout number
---@return any
async.sync = function(runner, timeout)
local done = false
local res = runner(function()
done = true
end)
vim.wait(timeout or 1000, function()
return done
end, 100, false)
return res
end
return async

View File

@@ -13,6 +13,7 @@ INVALID_CHARS[string.byte('[')] = true
INVALID_CHARS[string.byte(' ')] = true
INVALID_CHARS[string.byte('\t')] = true
INVALID_CHARS[string.byte('\n')] = true
INVALID_CHARS[string.byte('\r')] = true
local PAIR_CHARS = {}
PAIR_CHARS[string.byte('[')] = string.byte(']')