This kind of configuration applies to all projects the server is used for. Here, there are a number of ways to do this inside Eglot.
A common way is to pass command-line options to the server invocation
via eglot-server-programs
. Let’s say we want to configure
where the clangd
server reads its
compile_commands.json
from. This can be done like so:
(with-eval-after-load 'eglot (add-to-list 'eglot-server-programs `(c++-mode . ("clangd" "--compile-commands-dir=/tmp"))))
Another way is to have Eglot pass a JSON object to the server during
the LSP handshake. This is done using the
:initializationOptions
syntax of eglot-server-programs
:
(with-eval-after-load 'eglot (add-to-list 'eglot-server-programs `(c++-mode . ("clangd" :initializationOptions (:compilationDatabasePath "/tmp")))))
The argument (:compilationDatabasePath "/tmp")
is Emacs’s
representation in plist format of a simple JSON object
{"compilationDatabasePath": "/tmp"}
. To learn how to
represent more deeply nested options in this format, see JSONRPC objects in Elisp.
In this case, the two examples achieve exactly the same, but notice how the option’s name has changed between them.
Finally there is another way to do user-specific configuration of
language servers, which may be used if the methods above are not
supported. It consists of globally setting
eglot-workspace-configuration
, a variable originally intended
for project-specific configuration. This has the same effect as
giving all your projects a certain default configuration, as described
in Project-specific configuration. Here is an example:
(setq-default eglot-workspace-configuration '(:pylsp (:plugins (:jedi_completion (:include_params t :fuzzy t) :pylint (:enabled :json-false))) :gopls (:usePlaceholders t)))
Note that the global value of eglot-workspace-configuration
is
always overridden if a directory-local value is detected.