@@ -107,7 +107,7 @@ entry.get_word = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local word
|
local word
|
||||||
if misc.safe(self:get_completion_item().textEdit) then
|
if misc.safe(self:get_completion_item().textEdit) and not misc.empty(self:get_completion_item().textEdit.newText) then
|
||||||
word = str.trim(self:get_completion_item().textEdit.newText)
|
word = str.trim(self:get_completion_item().textEdit.newText)
|
||||||
if self:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
|
if self:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
|
||||||
word = vim.lsp.util.parse_snippet(word)
|
word = vim.lsp.util.parse_snippet(word)
|
||||||
@@ -116,7 +116,7 @@ entry.get_word = function(self)
|
|||||||
if 0 < overwrite[2] or self:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
|
if 0 < overwrite[2] or self:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
|
||||||
word = str.get_word(word, string.byte(self.context.cursor_after_line, 1), overwrite[1] or 0)
|
word = str.get_word(word, string.byte(self.context.cursor_after_line, 1), overwrite[1] or 0)
|
||||||
end
|
end
|
||||||
elseif misc.safe(self:get_completion_item().insertText) then
|
elseif not misc.empty(self:get_completion_item().insertText) then
|
||||||
word = str.trim(self:get_completion_item().insertText)
|
word = str.trim(self:get_completion_item().insertText)
|
||||||
if self:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
|
if self:get_completion_item().insertTextFormat == types.lsp.InsertTextFormat.Snippet then
|
||||||
word = str.get_word(vim.lsp.util.parse_snippet(word))
|
word = str.get_word(vim.lsp.util.parse_snippet(word))
|
||||||
@@ -362,7 +362,7 @@ entry.match = function(self, input, matching_config)
|
|||||||
|
|
||||||
-- Support the language server that doesn't respect VSCode's behaviors.
|
-- Support the language server that doesn't respect VSCode's behaviors.
|
||||||
if score == 0 then
|
if score == 0 then
|
||||||
if misc.safe(self:get_completion_item().textEdit) then
|
if misc.safe(self:get_completion_item().textEdit) and not misc.empty(self:get_completion_item().textEdit.newText) then
|
||||||
local diff = self.source_offset - self:get_offset()
|
local diff = self.source_offset - self:get_offset()
|
||||||
if diff > 0 then
|
if diff > 0 then
|
||||||
local prefix = string.sub(self.context.cursor_line, self:get_offset(), self:get_offset() + diff)
|
local prefix = string.sub(self.context.cursor_line, self:get_offset(), self:get_offset() + diff)
|
||||||
|
|||||||
@@ -264,6 +264,58 @@ describe('entry', function()
|
|||||||
assert.are.equal(e:get_filter_text(), '$this')
|
assert.are.equal(e:get_filter_text(), '$this')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('[odin-language-server] 1', function()
|
||||||
|
local state = spec.state('\t\t', 1, 4)
|
||||||
|
|
||||||
|
-- press g
|
||||||
|
state.input('s')
|
||||||
|
local e = entry.new(state.manual(), state.source(), {
|
||||||
|
additionalTextEdits = {},
|
||||||
|
command = {
|
||||||
|
arguments = {},
|
||||||
|
command = '',
|
||||||
|
title = '',
|
||||||
|
},
|
||||||
|
deprecated = false,
|
||||||
|
detail = 'string',
|
||||||
|
documentation = '',
|
||||||
|
insertText = '',
|
||||||
|
insertTextFormat = 1,
|
||||||
|
kind = 14,
|
||||||
|
label = 'string',
|
||||||
|
tags = {},
|
||||||
|
})
|
||||||
|
assert.are.equal(e:get_vim_item(e:get_offset()).word, 'string')
|
||||||
|
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(), {
|
||||||
|
detail = 'ansible.builtin',
|
||||||
|
filterText = 'blockinfile ansible.builtin.blockinfile',
|
||||||
|
kind = 7,
|
||||||
|
label = 'blockinfile',
|
||||||
|
sortText = '2_blockinfile',
|
||||||
|
textEdit = {
|
||||||
|
newText = '',
|
||||||
|
range = {
|
||||||
|
['end'] = {
|
||||||
|
character = 7,
|
||||||
|
line = 15,
|
||||||
|
},
|
||||||
|
start = {
|
||||||
|
character = 6,
|
||||||
|
line = 15,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.are.equal(e:get_vim_item(e:get_offset()).word, 'blockinfile')
|
||||||
|
end)
|
||||||
|
|
||||||
it('[#47] word should not contain \\n character', function()
|
it('[#47] word should not contain \\n character', function()
|
||||||
local state = spec.state('', 1, 1)
|
local state = spec.state('', 1, 1)
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,28 @@ misc.concat = function(list1, list2)
|
|||||||
return new_list
|
return new_list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Return the valu is empty or not.
|
||||||
|
---@param v any
|
||||||
|
---@return boolean
|
||||||
|
misc.empty = function(v)
|
||||||
|
if not v then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if v == vim.NIL then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if type(v) == 'string' and v == '' then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if type(v) == 'table' and vim.tbl_isempty(v) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if type(v) == 'number' and v == 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
---The symbol to remove key in misc.merge.
|
---The symbol to remove key in misc.merge.
|
||||||
misc.none = vim.NIL
|
misc.none = vim.NIL
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user