diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua index 1662139..1a6d086 100644 --- a/lua/cmp/entry.lua +++ b/lua/cmp/entry.lua @@ -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 diff --git a/lua/cmp/entry_spec.lua b/lua/cmp/entry_spec.lua index 3fe049d..08223b4 100644 --- a/lua/cmp/entry_spec.lua +++ b/lua/cmp/entry_spec.lua @@ -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) diff --git a/lua/cmp/source_spec.lua b/lua/cmp/source_spec.lua index ed86888..4f4335e 100644 --- a/lua/cmp/source_spec.lua +++ b/lua/cmp/source_spec.lua @@ -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) diff --git a/lua/cmp/utils/async.lua b/lua/cmp/utils/async.lua index 3484075..ed34b61 100644 --- a/lua/cmp/utils/async.lua +++ b/lua/cmp/utils/async.lua @@ -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 diff --git a/lua/cmp/utils/str.lua b/lua/cmp/utils/str.lua index b50e577..c0eb37d 100644 --- a/lua/cmp/utils/str.lua +++ b/lua/cmp/utils/str.lua @@ -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(']')