/eglot-x

Protocol extensions for Eglot

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

Protocol extensions for Eglot

Eglot supports (a subset of) the Language Server Protocol. However, there are useful protocol extensions that are not (yet) part of the official protocol specification. Eglot-x adds support for some of them.

Add the following line to your init file to enable eglot-x

    (with-eval-after-load 'eglot (require 'eglot-x))

To adjust which extensions are enabled:

    M-x customize-group RET eglot-x RET

Supported extensions

Files extension

The extension allows the client and the server to have separate file systems. For example, the server can run inside a Docker container, or the source code can be on a remote system accessed by Tramp. The client can send files to the server only from the result of project-files. The list of eligible files can further limited by eglot-x-files-visible-regexp and eglot-x-files-hidden-regexp. This feature works if project-roots and project-external-roots are set correctly.

Enabling extension disables Eglot's built-in support for Tramp files.

Additional reference methods

The command `eglot-x-find-refs' is the entry point for the extra methods. You can bind it to a key:

    (define-key eglot-mode-map (kbd "s-.") #'eglot-x-find-refs)

Currently, the ccls and rust-analyzer are the only servers whose extra reference methods eglot-x supports.

Encoding negotiation

The extension allows the client and the server to negotiate a proper encoding to be used in transmitting column positions.

rust-analyzer extensions

experimental extensions

  • Snippet TextEdits: see variable eglot-x-enable-snippet-text-edit.

  • Join Lines: see defun eglot-x-join-lines.

  • Move Item: see defun eglot-x-move-item-down and eglot-x-move-item-up.

  • On Enter: see defun eglot-x-on-enter.

  • Matching Brace: see eglot-x-matching-brace. However, emacs' own backward-sexp, and forward-sexp seem to be more useful.

  • Open External Documentation: see defun eglot-x-open-external-documentation.

  • Structural Search Replace (SSR): see defun eglot-x-structural-search-replace.

    The server checks the correctness of the query while you type:

    SSR

    The replacement process is similar to query-replace:

    SSR2

  • Workspace Symbols Filtering: see defun eglot-x-find-workspace-symbol.

    The xref buffer shows the current matches while the user iteratively types the query and another buffer shows the location of the first match.

    ws-symbol

    Additional input refines the results and the point in main.rs is changed once again to the location of the new first result:

    ws-symbol-2

    You can change the search scope and kind with C-l and C-M-l, respectively. See variable eglot-x-ws-keymap. The non-default settings are shown between braces:

    ws-symbol-3

    Currently, the xref buffer shows the first lines of the matches. This is not always helpful.

  • Runnables: see defun eglot-x-ask-runnables.

    Results for the whole buffer:

    runnables-1

    Selecting the first "runnable":

    runnables-2

    The "runnable" is executed as a compile-command:

    runnables-3

  • Server Status: see variable eglot-x-enable-server-status. The mode-line displays the status unless it is "permanently OK".

  • Inlay Hints: for an initial, basic support see defun eglot-x-insert-inlay-hint-at-point.

rust-analyzer specific extensions

  • Expand Macro: see defun eglot-x-expand-macro.

  • Related Tests: see defun eglot-x-ask-related-tests.

  • Reload Workspace: see defun eglot-x-reload-workspace.

  • View Crate Graph: see variable eglot-x-graph-type and defun eglot-x-view-crate-graph.

    crate-graph

    You can also jump to the crate (Cargo.toml) if the graph-type is not 'svg':

    crate-graph-2

rust-analyzer specific extensions for debugging rust-analyzer

  • Analyzer Status: see defun eglot-x-analyzer-status.

  • Syntax Tree: see defun eglot-x-show-syntax-tree.

    syntax-tree

  • View Hir: see defun eglot-x-view-hir.

  • (Memory Usage): see defun eglot-x-memory-usage.

License

GPLv3+