]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Add basic support for InsertReplaceEdit in completion reply. Fixes #354
authorYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 4 Jul 2023 17:46:21 +0000 (10:46 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Tue, 4 Jul 2023 17:46:21 +0000 (10:46 -0700)
autoload/lsp/capabilities.vim
autoload/lsp/completion.vim

index d2719e049e6d03198525bd9b61d2eb231db347f4..f29f250f64f0c95d9c6af207d5fa70c61526335f 100644 (file)
@@ -323,7 +323,8 @@ export def GetClientCaps(): dict<any>
        completionItem: {
          documentationFormat: ['markdown', 'plaintext'],
          resolveSupport: {properties: ['detail', 'documentation']},
-         snippetSupport: opt.lspOptions.snippetSupport
+         snippetSupport: opt.lspOptions.snippetSupport,
+         insertReplaceSupport: false
        },
        completionItemKind: {valueSet: range(1, 25)}
       },
index 5e38296e1ea8585a487137038cf3545080512cd6..13614d305845f0b828d17b9f6c9a54c13456424f 100644 (file)
@@ -191,7 +191,7 @@ export def CompletionReply(lspserver: dict<any>, cItems: any)
     var d: dict<any> = {}
 
     # 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<any>, cItems: any)
        start_charcol = chcol
       endif
       var textEdit = item.textEdit
+      var textEditRange: dict<any> = {}
+      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 : ]