From: Sebastian Poeplau <sebastian.poeplau@mailbox.org>
To: emacs-devel@gnu.org
Subject: eglot's interface for major modes
Date: Fri, 07 Apr 2023 20:20:03 +0200 [thread overview]
Message-ID: <874jpr35eh.fsf@mailbox.org> (raw)
I'm using eglot with the Ada Language Server [1]. The server exposes a
custom command "als-other-file", whose purpose is to jump between
specification and implementation, a bit like `ff-find-other-file' for C.
Upon receiving the command, the server sends a "window/showDocument"
request [2] to the client, specifying the file to open.
Here's the code I use:
(defun ada-light-other-file ()
"Jump from spec to body or vice versa using the Ada Language Server."
(interactive)
(if-let ((server (eglot-current-server)))
(eglot-execute-command server
"als-other-file"
(vector (eglot--TextDocumentIdentifier)))
(message "%s" "Not connected to the Ada Language Server")))
(unless (cl-find-method 'eglot-handle-request nil '(t (eql window/showDocument)))
(cl-defmethod eglot-handle-request
(_server (_method (eql window/showDocument)) &key uri &allow-other-keys)
(find-file (eglot--uri-to-path uri))
(list :success t)))
It works, but I wanted to discuss two things:
1. My function `ada-light-other-file' uses eglot's API
`eglot-execute-command', but I wasn't able to find a public function
that returns the document ID, hence my use of
`eglot--TextDocumentIdentifier'. Do you think it makes sense to add
one?
2. Should the handler for "window/showDocument" be part of eglot?
By the way, I edit Ada code with a custom major mode [3], but the actual
major mode being used shouldn't matter here.
[1] https://github.com/AdaCore/ada_language_server
[2] https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#window_showDocument
[3] https://github.com/sebastianpoeplau/ada-light-mode
next reply other threads:[~2023-04-07 18:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 18:20 Sebastian Poeplau [this message]
2023-04-07 21:26 ` eglot's interface for major modes Stephen Leake
2023-04-08 9:13 ` Felician Nemeth
2023-04-08 9:37 ` Sebastian Poeplau
2023-04-11 14:05 ` Felician Nemeth
2023-04-13 19:24 ` Sebastian Poeplau
2023-04-13 16:22 ` João Távora
2023-04-13 17:43 ` Felician Nemeth
2023-04-13 19:36 ` Sebastian Poeplau
2023-04-08 9:26 ` Sebastian Poeplau
2023-04-08 10:30 ` Stephen Leake
2023-04-08 10:53 ` Sebastian Poeplau
2023-04-12 23:06 ` Stephen Leake
2023-04-13 19:23 ` Sebastian Poeplau
2023-04-15 16:38 ` Stephen Leake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874jpr35eh.fsf@mailbox.org \
--to=sebastian.poeplau@mailbox.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).