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

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

[elpa] 1.2 fc9bbf7 096/101: Fix #160: Properly delete inserted text afte


From: Christian Johansson
Subject: [elpa] 1.2 fc9bbf7 096/101: Fix #160: Properly delete inserted text after completion
Date: Thu, 29 Apr 2021 15:09:08 -0400 (EDT)

tag: 1.2
commit fc9bbf76e3b82072407f40cb07f5b0b726ed5ace
Author: MichaƂ Krzywkowski <k.michal@zoho.com>
Commit: mkcms <k.michal@zoho.com>

    Fix #160: Properly delete inserted text after completion
    
    * eglot.el (eglot-completion-at-point): In :exit-function, delete only
      the region of buffer that was inserted by completion.
---
 eglot.el | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/eglot.el b/eglot.el
index d9c1c3a..c65d908 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1543,6 +1543,7 @@ is not active."
                               (string-trim-left label))
                              (t
                               (or insertText (string-trim-left label))))))
+                  (setq all (append all `(:bounds ,bounds)))
                   (add-text-properties 0 1 all completion)
                   (put-text-property 0 1 'eglot--lsp-completion all completion)
                   completion))
@@ -1604,13 +1605,19 @@ is not active."
                                         insertText
                                         textEdit
                                         additionalTextEdits
+                                        bounds
                                         &allow-other-keys)
                (text-properties-at 0 comp)
              (let ((fn (and (eql insertTextFormat 2)
                             (eglot--snippet-expansion-fn))))
                (when (or fn textEdit)
-                 ;; Undo the completion
-                 (delete-region (- (point) (length comp)) (point)))
+                 ;; Undo the completion.  If before completion the buffer was
+                 ;; "foo.b" and now is "foo.bar", `comp' will be "bar".  We
+                 ;; want to delete only "ar" (`comp' minus the symbol whose
+                 ;; bounds we've calculated before) (github#160).
+                 (delete-region (+ (- (point) (length comp))
+                                   (if bounds (- (cdr bounds) (car bounds)) 0))
+                                (point)))
                (cond (textEdit
                       (cl-destructuring-bind (&key range newText) textEdit
                         (pcase-let ((`(,beg . ,end) (eglot--range-region 
range)))



reply via email to

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