unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Richard Copley <rcopley@gmail.com>
Cc: 66759@debbugs.gnu.org
Subject: bug#66759: 30.0.50; Flymake (with Eglot) error cleaning up old overlay
Date: Thu, 26 Oct 2023 14:27:42 +0100	[thread overview]
Message-ID: <87pm111pkh.fsf@gmail.com> (raw)
In-Reply-To: <CAPM58oi_rchPoYTs5enoXkiVMeeDBYOiEo3Z8Oh4fV_9XJqV7g@mail.gmail.com> (Richard Copley's message of "Thu, 26 Oct 2023 13:09:07 +0100")

Richard Copley <rcopley@gmail.com> writes:

> I'm afraid I'm unable to consistently reproduce this error. I hope you
> can see the issue and devise a testcase from the following
> description.

Thanks very much for this report.  This problem could be the same as
https://github.com/joaotavora/eglot/discussions/1311, at least it its
most recent iteration.

Anyway, I think your analysis of the code is excellent and your
conjecture (for at least one possible cause of this problem) is very
promising.  That "don't bother with invalid bounds" was introduced
recently:

   commit 8b1947ffdd9d9eae26a308f0abaac45e06baac22
   Author: João Távora <joaotavora@gmail.com>
   Date:   Thu Sep 21 00:03:32 2023 +0100
    
       Flymake: more fixes to flymake--highlight-line
       
       Make it robust to diagonstics with invalid bounds.
       
       * lisp/progmodes/flymake.el (flymake--highlight-line): Robustify.
    
   diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
   --- a/lisp/progmodes/flymake.el
   +++ b/lisp/progmodes/flymake.el
   @@ -781,1 +782,5 @@
   -    (setq ov (make-overlay end beg))
   +    (when (= (overlay-start ov) (overlay-end ov))
   +      ;; Some backends report diagnostics with invalid bounds.  Don't
   +      ;; bother.
   +      (delete-overlay ov)
   +      (cl-return-from flymake--highlight-line nil)):


And indeed the flymake--diag-overlay slot is not filled in when we get
this early return.  And indeed the overlays considered for deletion are
the ones stored in the "state" map, meaning everything the backend
reported.

So maybe this patch is all that's needed:

diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index b27e6527f81..9be40499d37 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -809,6 +809,7 @@ flymake--highlight-line
                         (flymake--diag-orig-end e))
                   (flymake--delete-overlay eov)))
     (setq ov (make-overlay beg end))
+    (setf (flymake--diag-overlay diagnostic) ov)
     (when (= (overlay-start ov) (overlay-end ov))
       ;; Some backends report diagnostics with invalid bounds.  Don't
       ;; bother.
@@ -863,7 +864,6 @@ flymake--highlight-line
     (overlay-put ov 'evaporate t)
     (overlay-put ov 'flymake-overlay t)
     (overlay-put ov 'flymake-diagnostic diagnostic)
-    (setf (flymake--diag-overlay diagnostic) ov)
     ;; Handle `flymake-show-diagnostics-at-end-of-line'
     ;;
     (when flymake-show-diagnostics-at-end-of-line


There's a fair chance this fixes the bug effectively, but even if it
doesn't, it is nevertheless a solid change, so I've pushed it and bumped
the Flymake ELPA package version.

Please keep an eye out of this bug.

What language server are you using with Eglot btw?

> A possible fix is to check if `flymake--highlight-line' created an
> overlay before inserting a diagnostic into `flymake--state-diags',
> in phase 2.

This could also work, but is slightly more complex.  And it would
destroy the invariant that that list contains every "domestic"
diagnostic reported by the backend (even invalid ones).

João





  reply	other threads:[~2023-10-26 13:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-26 12:09 bug#66759: 30.0.50; Flymake (with Eglot) error cleaning up old overlay Richard Copley
2023-10-26 13:27 ` João Távora [this message]
2023-10-26 14:17   ` Richard Copley
2023-10-26 17:10     ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pm111pkh.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=66759@debbugs.gnu.org \
    --cc=rcopley@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).