From 7873adf9a8d283554d305d230594eb477e021f8d Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Tue, 24 Aug 2021 13:23:27 +0900 Subject: [PATCH] Fix #47 --- lua/cmp/entry.lua | 5 ++--- lua/cmp/entry_spec.lua | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lua/cmp/entry.lua b/lua/cmp/entry.lua index 9d7f187..d4bb146 100644 --- a/lua/cmp/entry.lua +++ b/lua/cmp/entry.lua @@ -109,11 +109,10 @@ entry.get_word = function(self) end elseif misc.safe(self.completion_item.insertText) then word = str.trim(self.completion_item.insertText) - if self.completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet then - word = str.get_word(word) - end + word = str.get_word(word) else word = str.trim(self.completion_item.label) + word = str.get_word(word, '') end return word end) diff --git a/lua/cmp/entry_spec.lua b/lua/cmp/entry_spec.lua index f3db891..3fe049d 100644 --- a/lua/cmp/entry_spec.lua +++ b/lua/cmp/entry_spec.lua @@ -243,7 +243,6 @@ describe('entry', function() -- press g state.input('$') local e = entry.new(state.manual(), state.source(), { - detail = '\\Nico_URLConf', kind = 6, label = '$this', sortText = '$this', @@ -264,4 +263,19 @@ describe('entry', function() assert.are.equal(e:get_vim_item(e:get_offset()).word, '$this') assert.are.equal(e:get_filter_text(), '$this') end) + + it('[#47] word should not contain \\n character', function() + local state = spec.state('', 1, 1) + + -- press g + state.input('_') + local e = entry.new(state.manual(), state.source(), { + kind = 6, + label = '__init__', + 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_filter_text(), '__init__') + end) end)