emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

eglot's interface for major modes


From: Sebastian Poeplau
Subject: eglot's interface for major modes
Date: Fri, 07 Apr 2023 20:20:03 +0200

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]