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]> |
João Távora <[email protected]> writes: > 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. This patch won't work, don't bother, but the one after my signature will. The reason I know is that I tested myself: git clone https://github.com/brownts/ada-ts-mode.git cd ada-ts-mode curl -LO https://github.com/AdaCore/ada_language_server/releases/download/2026.3.202607051/als-2026.3.202607051-linux-x64.tar.gz tar xvfz als-2026.3.202607051-linux-x64.tar.gz PATH=$PATH:$PWD/integration/vscode/ada/x64/linux /path/to/emacs -Q -L . \ -l ada-ts-mode -l ada-ts-lspclient-eglot \ test/resources/hello_world/hello_world.ads -f eglot C-c C-o (This, btw, is what a MRE should look like for future bug reports. It relieves me from wading through this stuff and lets me focus on the problem.) However, in my machine I couldn't reproduce the problem. C-c C-o works fine regardless of the size of the file. What exactly is the breakage I'm looking for? Can you supply an incantation similar to the one above that is guaranteed (or almost guaranteed) to fail? 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) + (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) + (run-at-time #'findit 0 nil)))) (t (setq success :json-false))) `(:success ,success)))