Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Commit 7138fd9

Browse files
authored
Merge pull request #125 from kdheepak/kd/fix-lsp-completion-for-snippets
Fix LSP completion when applying a `TextEdit` with `newText`
2 parents d28179c + 5f6e320 commit 7138fd9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lua/source/lsp.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ M.getCompletionItems = function(_, _)
1010
return M.items
1111
end
1212

13-
local function get_completion_word(item)
13+
local function get_completion_word(item, prefix)
1414
if item.textEdit ~= nil and item.textEdit ~= vim.NIL
1515
and item.textEdit.newText ~= nil and (item.insertTextFormat ~= 2 or vim.fn.exists('g:loaded_vsnip_integ')) then
16-
return item.textEdit.newText
16+
local start_range = item.textEdit.range["start"]
17+
local end_range = item.textEdit.range["end"]
18+
if start_range.line == end_range.line and start_range.character == end_range.character then
19+
return prefix .. item.textEdit.newText
20+
else
21+
return item.textEdit.newText
22+
end
1723
elseif item.insertText ~= nil and item.insertText ~= vim.NIL then
1824
return item.insertText
1925
end
@@ -49,7 +55,7 @@ local function text_document_completion_list_to_complete_items(result, prefix)
4955
end
5056
item.info = info
5157

52-
item.word = get_completion_word(completion_item)
58+
item.word = get_completion_word(completion_item, prefix)
5359
item.user_data = {
5460
lsp = {
5561
completion_item = completion_item

0 commit comments

Comments
 (0)