]> git.eshelyaron.com Git - emacs.git/commitdiff
Add support for textedits in completion
authorMichal Krzywkowski <k.michal@zoho.com>
Wed, 31 Oct 2018 19:59:30 +0000 (20:59 +0100)
committerMichal Krzywkowski <k.michal@zoho.com>
Tue, 13 Nov 2018 11:39:12 +0000 (12:39 +0100)
* eglot.el (eglot-completion-at-point): Apply the CompletionItem's
  :textEdit and :additionalTextEdits when they're present.

lisp/progmodes/eglot.el

index 24f8c971f91acd3a5df1c23071c4656fac106363..d4a8b6f8a33f6c1d2c179c2047b1ba666a1b30f3 100644 (file)
@@ -1584,12 +1584,23 @@ is not active."
                        (cl-find comp strings :test #'string=))))
            (cl-destructuring-bind (&key insertTextFormat
                                         insertText
+                                        textEdit
+                                        additionalTextEdits
                                         &allow-other-keys)
                (text-properties-at 0 comp)
-             (when-let ((fn (and (eql insertTextFormat 2)
-                                 (eglot--snippet-expansion-fn))))
-               (delete-region (- (point) (length comp)) (point))
-               (funcall fn insertText))
+             (let ((fn (and (eql insertTextFormat 2)
+                            (eglot--snippet-expansion-fn))))
+               (when (or fn textEdit)
+                 ;; Undo the completion
+                 (delete-region (- (point) (length comp)) (point)))
+               (cond (textEdit
+                      (cl-destructuring-bind (&key range newText) textEdit
+                        (pcase-let ((`(,beg . ,end) (eglot--range-region range)))
+                          (delete-region beg end)
+                          (goto-char beg)
+                          (funcall (or fn #'insert) newText)))
+                      (eglot--apply-text-edits additionalTextEdits))
+                     (fn (funcall fn insertText))))
              (eglot--signal-textDocument/didChange)
              (eglot-eldoc-function))))))))