emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot fdb1941 36/45: Add support for TextEdits in compl


From: João Távora
Subject: [elpa] externals/eglot fdb1941 36/45: Add support for TextEdits in completion
Date: Thu, 22 Nov 2018 19:15:32 -0500 (EST)

branch: externals/eglot
commit fdb1941fb01d590ad67092fb83fdbbd474e3d6f1
Author: Michał Krzywkowski <address@hidden>
Commit: mkcms <address@hidden>

    Add support for TextEdits in completion
    
    * eglot.el (eglot-completion-at-point): Apply the CompletionItem's
      :textEdit and :additionalTextEdits when they're present.
---
 eglot.el | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/eglot.el b/eglot.el
index 24f8c97..d4a8b6f 100644
--- a/eglot.el
+++ b/eglot.el
@@ -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))))))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]