emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master d3a17a58fbd: Eglot: rework eglot-handle-request (bug#62116)


From: João Távora
Subject: master d3a17a58fbd: Eglot: rework eglot-handle-request (bug#62116)
Date: Tue, 16 May 2023 14:21:48 -0400 (EDT)

branch: master
commit d3a17a58fbdb3482512264cebda2b6e8ae16b34e
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Eglot: rework eglot-handle-request (bug#62116)
    
    Address comments in the bug tracker regarding widening, and
    prematurely reporting success to the server before knowing if the file
    can indeed be shown.
    
    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=62116#70
    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=62116#79
    
    * lisp/progmodes/eglot.el (eglot-handle-request): Rework.
---
 lisp/progmodes/eglot.el | 42 +++++++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 52f87c1af5d..a65795f1dfc 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2371,23 +2371,31 @@ THINGS are either registrations or unregisterations 
(sic)."
   (_server (_method (eql window/showDocument)) &key
            uri external takeFocus selection)
   "Handle request window/showDocument."
-  (if (eq external t) (browse-url uri)
-    ;; Use run-with-timer to avoid nested client requests like the
-    ;; synchronous imenu case caused by which-func-mode.
-    (run-with-timer
-     0 nil
-     (lambda ()
-       (with-current-buffer (find-file-noselect (eglot--uri-to-path uri))
-         (cond (takeFocus
-                (pop-to-buffer (current-buffer))
-                (select-frame-set-input-focus (selected-frame)))
-               ((display-buffer (current-buffer))))
-         (when selection
-           (eglot--widening
-            (pcase-let ((`(,beg . ,end) (eglot--range-region selection)))
-              (goto-char beg)
-              (pulse-momentary-highlight-region beg end 'highlight))))))))
-  '(:success t))
+  (let ((success t)
+        (filename))
+    (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
+             (pcase-let ((`(,beg . ,end) (eglot--range-region selection)))
+               ;; FIXME: it is very naughty to use someone else's `--'
+               ;; function, but `xref--goto-char' happens to have
+               ;; exactly the semantics we want vis-a-vis widening.
+               (xref--goto-char beg)
+               (pulse-momentary-highlight-region beg end 'highlight)))))))
+     (t (setq success :json-false)))
+    `(:success ,success)))
 
 (defun eglot--TextDocumentIdentifier ()
   "Compute TextDocumentIdentifier object for current buffer."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]