tag: 1.2
commit fc9bbf76e3b82072407f40cb07f5b0b726ed5ace
Author: MichaĆ Krzywkowski <[email protected]>
Commit: mkcms <[email protected]>
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)))