]> git.eshelyaron.com Git - emacs.git/commitdiff
Eglot: fix edge case when deleting inlay hint overlays
authorJoão Távora <joaotavora@gmail.com>
Thu, 27 Apr 2023 19:51:07 +0000 (20:51 +0100)
committerJoão Távora <joaotavora@gmail.com>
Thu, 27 Apr 2023 23:39:08 +0000 (00:39 +0100)
When asked to update hints in a region (FROM TO),
eglot--update-hints-1 first deletes the existing hints.  It must
however take care to delete all overlays that logically belong to the
region, even if they don't physically belong to it, e.g. inlay
overlays spanning (FROM-1 FROM) and having a 'after-string' property.

* lisp/progmodes/eglot.el (eglot--update-hints-1): Fix edge case.

lisp/progmodes/eglot.el

index ed5540870847a576d68dd3afd019109862afc3ae..0fab8db0e8354fad5fca2ae51031f6a39dd5a78c 100644 (file)
@@ -3664,7 +3664,19 @@ If NOERROR, return predicate, else erroring function."
      :success-fn (lambda (hints)
                    (eglot--when-live-buffer buf
                      (eglot--widening
-                      (remove-overlays from to 'eglot--inlay-hint t)
+                      ;; Overlays ending right at FROM with an
+                      ;; `after-string' property logically belong to
+                      ;; the (FROM TO) region.  Likewise, such
+                      ;; overlays ending at TO don't logically belong
+                      ;; to it.
+                      (dolist (o (overlays-in (1- from) to))
+                        (when (and (overlay-get o 'eglot--inlay-hint)
+                                   (cond ((eq (overlay-end o) from)
+                                          (overlay-get o 'after-string))
+                                         ((eq (overlay-end o) to)
+                                          (overlay-get o 'before-string))
+                                         (t)))
+                          (delete-overlay o)))
                       (mapc paint-hint hints))))
      :deferred 'eglot--update-hints-1)))