From b8a37710852c43f1f9bee88b086810e7f0869d29 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Tue, 4 Jul 2023 10:46:21 -0700 Subject: [PATCH] Add basic support for InsertReplaceEdit in completion reply. Fixes #354 --- autoload/lsp/capabilities.vim | 3 ++- autoload/lsp/completion.vim | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/autoload/lsp/capabilities.vim b/autoload/lsp/capabilities.vim index d2719e0..f29f250 100644 --- a/autoload/lsp/capabilities.vim +++ b/autoload/lsp/capabilities.vim @@ -323,7 +323,8 @@ export def GetClientCaps(): dict completionItem: { documentationFormat: ['markdown', 'plaintext'], resolveSupport: {properties: ['detail', 'documentation']}, - snippetSupport: opt.lspOptions.snippetSupport + snippetSupport: opt.lspOptions.snippetSupport, + insertReplaceSupport: false }, completionItemKind: {valueSet: range(1, 25)} }, diff --git a/autoload/lsp/completion.vim b/autoload/lsp/completion.vim index 5e38296..13614d3 100644 --- a/autoload/lsp/completion.vim +++ b/autoload/lsp/completion.vim @@ -191,7 +191,7 @@ export def CompletionReply(lspserver: dict, cItems: any) var d: dict = {} # TODO: Add proper support for item.textEdit.newText and - # item.textEdit.range Keep in mind that item.textEdit.range can start be + # item.textEdit.range. Keep in mind that item.textEdit.range can start # way before the typed keyword. if item->has_key('textEdit') && lspOpts.completionMatcherValue != opt.COMPLETIONMATCHER_FUZZY @@ -202,8 +202,14 @@ export def CompletionReply(lspserver: dict, cItems: any) start_charcol = chcol endif var textEdit = item.textEdit + var textEditRange: dict = {} + if textEdit->has_key('range') + textEditRange = textEdit.range + elseif textEdit->has_key('insert') + textEditRange = textEdit.insert + endif var textEditStartCol = - util.GetCharIdxWithoutCompChar(bufnr(), textEdit.range.start) + util.GetCharIdxWithoutCompChar(bufnr(), textEditRange.start) if textEditStartCol != start_charcol var offset = start_charcol - textEditStartCol - 1 d.word = textEdit.newText[offset : ] -- 2.48.1