diff options
author | Felicián Németh <felician.nemeth@gmail.com> | 2023-05-12 01:50:05 +0100 |
---|---|---|
committer | João Távora <joaotavora@gmail.com> | 2023-05-13 13:02:30 +0100 |
commit | c083fa5cf80f711ac43dca1b6582aff1ad526e8e (patch) | |
tree | b8e0f25408a801f5218e2f60a4cd260ccd0a3554 | |
parent | ea986a64b234c3e946d4577dc2ccfd261855c60b (diff) | |
download | emacs-c083fa5cf80f711ac43dca1b6582aff1ad526e8e.tar.gz |
Eglot: support window/showRequest (bug#62116)
Co-authored-by: João Távora
* lisp/progmodes/eglot.el (eglot-client-capabilities): Advertise
window/showDocument.
(eglot-handle-request window/showDocument): New handler.
-rw-r--r-- | lisp/progmodes/eglot.el | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 66d893a14b5..52f87c1af5d 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -845,7 +845,8 @@ ACTION is an LSP object of either `CodeAction' or `Command' type." `(:valueSet [,@(mapcar #'car eglot--tag-faces)]))) - :window `(:workDoneProgress t) + :window `(:showDocument (:support t) + :workDoneProgress t) :general (list :positionEncodings ["utf-32" "utf-8" "utf-16"]) :experimental eglot--{}))) @@ -2366,6 +2367,28 @@ THINGS are either registrations or unregisterations (sic)." "Handle server request workspace/workspaceFolders." (eglot-workspace-folders server)) +(cl-defmethod eglot-handle-request + (_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)) + (defun eglot--TextDocumentIdentifier () "Compute TextDocumentIdentifier object for current buffer." `(:uri ,(eglot--path-to-uri (or buffer-file-name |