From 468a8104183ba46f92d0a194862761c81943c505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= Date: Sat, 22 Apr 2023 10:49:17 +0200 Subject: [PATCH] Eglot: support window/showDocument request * eglot.el (eglot-client-capabilities): Add showDocument support. (eglot-handle-request window/showDocument): New cl-defmethod. --- lisp/progmodes/eglot.el | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 3134d55fc0..daabb4ff7b 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -830,7 +830,8 @@ eglot-client-capabilities `(: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--{}))) @@ -2345,6 +2346,28 @@ eglot-handle-request "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) + (let ((filename (eglot--uri-to-path uri))) + (if (eq takeFocus t) + (find-file filename) + (find-file-noselect filename)) + (when selection + (with-current-buffer (get-file-buffer filename) + (save-restriction + (widen) + (pcase-let ((`(,beg . ,end) (eglot--range-region selection))) + (if (equal beg end) + (goto-char beg) + (goto-char end) + (set-mark-command nil) + (goto-char beg)))))))) + '(:success t)) + (defun eglot--TextDocumentIdentifier () "Compute TextDocumentIdentifier object for current buffer." `(:uri ,(eglot--path-to-uri (or buffer-file-name -- 2.30.2