]> git.eshelyaron.com Git - emacs.git/commitdiff
Correctly insert textedit-less snippets
authorJoão Távora <joaotavora@gmail.com>
Thu, 22 Nov 2018 23:07:18 +0000 (23:07 +0000)
committerJoão Távora <joaotavora@gmail.com>
Thu, 22 Nov 2018 23:07:18 +0000 (23:07 +0000)
Fixes a slight regression from https://github.com/joaotavora/eglot/issues/160.

* eglot.el (eglot-completion-at-point): When there is plain
`insertText' snippet, delete the full completion text.

GitHub-reference: fix https://github.com/joaotavora/eglot/issues/167

lisp/progmodes/eglot.el

index f4a02ac7a9274701498afbcc9abd8b48ef96ae2c..9ff9cdf6f57ed62f5a962eaceb75611176300f2a 100644 (file)
@@ -1612,24 +1612,31 @@ is not active."
                                         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.  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)))
+             (let ((snippet-fn (and (eql insertTextFormat 2)
+                                    (eglot--snippet-expansion-fn))))
                (cond (textEdit
+                      ;; Undo the just the completed bit.  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))
                       (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)))
+                          (funcall (or snippet-fn #'insert) newText)))
                       (eglot--apply-text-edits additionalTextEdits))
-                     (fn (funcall fn insertText))))
+                     (snippet-fn
+                      ;; A snippet should be inserted, but using plain
+                      ;; `insertText'.  This requires us to delete the
+                      ;; whole completion, since `insertText' is the full
+                      ;; completion's text.
+                      (delete-region (- (point) (length comp)) (point))
+                      (funcall snippet-fn insertText))))
              (eglot--signal-textDocument/didChange)
              (eglot-eldoc-function))))))))