Next: , Previous: , Up: Eglot   [Contents][Index]

6 Extending Eglot

Sometimes it may be useful to extend existing Eglot functionality using Elisp its public methods. A good example of when this need may arise is adding support for a custom LSP protocol extension only implemented by a specific server.

The best source of documentation for this is probably Eglot source code itself, particularly the section marked “API”.

Most of the functionality is implemented with Common-Lisp style generic functions (see Generics in EIEIO) that can be easily extended or overridden. The Eglot code itself is an example on how to do this.

The following is a relatively simple example that adds support for the inactiveRegions experimental feature introduced in version 17 of the clangd C/C++ language server++.

Summarily, the feature works by first having the server detect the Eglot’s advertisement of the inactiveRegions client capability during startup, whereupon the language server will report a list of regions of inactive code for each buffer. This is usually code surrounded by C/C++ #ifdef macros that the preprocessor removes based on compile-time information.

The language server reports the regions by periodically sending a textDocument/inactiveRegions notification for each managed buffer (see Buffers, Projects, and Eglot). Normally, unknown server notifications are ignored by Eglot, but we’re going change that.

Both the announcement of the client capability and the handling of the new notification is done by adding methods to generic functions.

After evaluating these two additions and reconnecting to the clangd language server (version 17), the result will be that all the inactive code in the buffer will be nicely grayed out using the LSP server knowledge about current compile time preprocessor defines.

Next: Troubleshooting Eglot, Previous: Advanced server configuration, Up: Eglot   [Contents][Index]