3.1 Eglot Features ¶
While Eglot is enabled in a buffer, it is said to be managing it,
using LSP and the specific capabilities of the language server to
activate and enhance modern IDE features in Emacs. Some of these
features are provided via other Emacs packages, and some via Eglot
directly (see Eglot Commands).
Here’s an overview of the main features that Eglot provides:
- At-point documentation: when point is near a symbol or an identifier,
information about the identifier’s significance in the program (its
function or method signature, its type, its custom documentation string,
etc.) is made available via the ElDoc package (see Programming
Language Doc in GNU Emacs Manual).
- On-the-fly diagnostic annotations, via the Flymake package
(see GNU Flymake manual ). Eglot’s Flymake backend
replaces other Flymake backends while it is managing a buffer, and
enhances diagnostics with interactive server-suggested fixes (so-called
code actions, see Eglot Commands).
- Finding definitions and uses of identifiers, via Xref (see Xref in GNU Emacs Manual). Eglot provides a backend for the Xref
capabilities which uses the language server’s understanding of the
program source. In particular, it eliminates the need to generate tags
tables (see Tags tables in GNU Emacs Manual) for languages
which are only supported by the
etags backend.
- Buffer navigation by name of function, class, method, etc., via Imenu
(see Imenu in GNU Emacs Manual). Eglot provides its own
variant of
imenu-create-index-function, which generates the index
for the buffer based on the language server’s program source analysis.
- Enhanced completion of symbol at point by the
completion-at-point
command (see Symbol Completion in GNU Emacs Manual). This
uses the language server’s parser data for the completion candidates.
- Server-suggested code refactorings. The ElDoc package is also leveraged
to retrieve so-called code actions nearby point. When such
suggestions are available they are annotated with a special indication
and can be easily invoked by the user with the
eglot-code-action
command (see Eglot Commands).
- On-the-fly succinct informative annotations, so-called inlay
hints. Eglot adds special intangible text nearby certain identifiers,
be it the type of a variable, or the name of a formal parameter in a
function call. See Eglot Commands, and the
eglot-inlay-hints-mode minor mode.
- Enhanced source code fontification via LSP semantic tokens. Eglot
can leverage the language server’s understanding of the role and meaning
of identifiers in the code to provide more accurate syntax highlighting.
See Eglot Commands, and the
eglot-semantic-tokens-mode minor
mode.
- Display of function call and type hierarchies via the
eglot-show-call-hierarchy and eglot-show-type-hierarchy
commands (see Eglot Commands).
- Code reformatting via the
eglot-format and related commands
(see Eglot Commands). Automatic reformatting of source code is also
supported and is activated automatically as you type.
- Eglot enhances symbol completion front-ends by providing completion
candidates based on the language server’s understanding of the source
code (see Symbol Completion in GNU Emacs Manual). The
Company package, installable from GNU ELPA, is a popular package known
to work well with Eglot.
- If YASnippet, a popular third-party package for automatic insertion of
code templates (snippets), is installed, and the language server
supports snippet completion candidates, Eglot arranges for the
completion package to instantiate these snippets using YASnippet.
(YASnippet can be installed from GNU ELPA.)
- When the server provides at-point documentation formatted as Markdown in
addition to plain text, Eglot arranges for the ElDoc package to enrich
this text with fontifications, hyperlinks and other nice formatting
before displaying it to the user. This makes the documentation shown by
ElDoc look nicer on display.
- In addition to enabling and enhancing other features and packages, Eglot
also provides a number of user commands based on the capabilities of
language servers. Examples include renaming symbols with
eglot-rename and asking to automatically correct problems with
eglot-code-actions. See Eglot Commands.
Not all servers support the full set of LSP capabilities, but most of
them support enough to enable the basic set of features mentioned above.
Conversely, some servers offer capabilities for which no equivalent
Emacs package exists yet, and so Eglot cannot (yet) expose these
capabilities to Emacs users. However, See Extending Eglot.
Finally, it’s worth noting that, by default, Eglot generally turns on
all features that it can turn on. It’s possible to opt out of
features via the eglot-ignored-server-capabilities user option
(see Customizing Eglot) and the eglot-managed-mode-hook hook
that runs after Eglot starts managing a buffer (see Buffers, Projects, and Eglot).