unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* eglot's interface for major modes
@ 2023-04-07 18:20 Sebastian Poeplau
  2023-04-07 21:26 ` Stephen Leake
  0 siblings, 1 reply; 15+ messages in thread
From: Sebastian Poeplau @ 2023-04-07 18:20 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-04-15 16:38 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-07 18:20 eglot's interface for major modes Sebastian Poeplau
2023-04-07 21:26 ` 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

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).