summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Távora <joaotavora@gmail.com>2023-05-16 19:23:33 +0100
committerJoão Távora <joaotavora@gmail.com>2023-05-16 19:23:57 +0100
commitd3a17a58fbdb3482512264cebda2b6e8ae16b34e (patch)
treeecd23295c860122d9b607fdf95a36a937eb19311
parenta8f2009d03138b3b3b6c75452aba7a17c68a60f7 (diff)
downloademacs-d3a17a58fbdb3482512264cebda2b6e8ae16b34e.tar.gz
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.
-rw-r--r--lisp/progmodes/eglot.el42
1 files 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."