bug#81538: 32.0.50; Eglot: Non-local exit during window/showDocument handling

João Távora <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
Troy Brown <[email protected]> writes:

>> I still think you're misanalysing the situation. Please reduce the delay in the "silly patch" I have sent from 100ms to just 1ms. And try again the reproduce.
>
> I ran tests with both 1ms and 0.1ms delays.  It failed occasionally
> with a 1ms delay, but failed often with a 0.1ms delay.

Maybe _I_ was misanalysing the situation.  Try the patch after my sig,
please.

João

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index b27d7761111..1e10e1c9d4e 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2961,19 +2961,21 @@ eglot-handle-request
     (cond
      ((eq external t) (browse-url uri))
      ((file-readable-p (setq filename (eglot-uri-to-path uri)))
-      ;; Use run-with-timer to avoid nested client requests like the
-      ;; "synchronous imenu" floated in bug#62116 presumably caused by
-      ;; which-func-mode.
-      (run-with-timer
-       0 nil
-       (lambda ()
-         (with-current-buffer (find-file-noselect filename)
-           (cond (takeFocus
-                  (pop-to-buffer (current-buffer))
-                  (select-frame-set-input-focus (selected-frame)))
-                 ((display-buffer (current-buffer))))
-           (when selection
-             (eglot--goto selection))))))
+      ;; Really ensure this runs when it is safe to run it.
+      ;; run-with-timer avoid nested client requests like the
+      ;; "synchronous imenu" floated in bug#62116 while the
+      ;; "post-command once" trick is for bug#81538.
+      (cl-labels ((findit ()
+                  (remove-hook 'post-command-hook #'findit t)
+                  (with-current-buffer (find-file-noselect filename)
+                    (cond (takeFocus
+                           (pop-to-buffer (current-buffer))
+                           (select-frame-set-input-focus (selected-frame)))
+                          ((display-buffer (current-buffer))))
+                    (when selection
+                      (eglot--goto selection)))))
+                (if this-command (add-hook 'post-command-hook #'findit nil t)
+                  (run-at-time #'findit 0 nil))))
      (t (setq success :json-false)))
     `(:success ,success)))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.