reddit / emacs

Eglot configuration with `clangd`

jvillasante · 2022-10-31 19:56
Hello, I'm trying `eglot` on emacs-29 which I configure like follows (mostly for C++): ``` (progn (customize-set-variable 'eglot-autoshutdown t) (customize-set-variable 'eglot-extend-to-xref t) (customize-set-variable 'eglot-ignored-server-capabilities (quote (:documentFormattingProvider :documentRangeFormattingProvider))) (with-eval-after-load 'eglot (setq completion-category-defaults nil) (add-to-list 'eglot-server-programs '(c-mode c++-mode . ("clangd" "-j=4" "--malloc-trim" "--log=error" "--background-index" "--clang-tidy" "--cross-file-rename" "--completion-style=detailed" "--pch-storage=memory" "--header-insertion=never" "--header-insertion-decorators=0")))) (add-hook 'c-mode-hook #'eglot-ensure) (add-hook 'c++-mode-hook #'eglot-ensure) (add-hook 'rustic-mode-hook #'eglot-ensure)) ``` Things seem to work, however, even when I have requested `clangd` to not do header insertion `--header-insertion=never`, `eglot` keeps inserting headers for me. How can I disable this behaviour or I'm I doing something wrong? For example, if I'm on a C++ buffer and I type `std::vector` then `eglot` will go ahead and add `#include <vector>` which I don't want at all.
holgerschurig · 2022-10-31 21:27
The header insertion thing sounds like a clangd bug. Maybe you should write a bug report,or try a newer version of clangd (on Debian, I can use nightlys).
jvillasante · 2022-10-31 21:35
I don't think so, it does work correctly with `lsp-mode`. I'm using a very recent version of `clangd` with Fedora: ``` clangd version 14.0.5 (Fedora 14.0.5-1.fc36) Features: linux Platform: x86_64-unknown-linux-gnu; target=x86_64-redhat-linux-gnu ```
lispers-anonymous · 2022-10-31 22:13
Check the existing `eglot-server-programs`. The default ones might be picked up instead of yours, or you aren't using the right syntax. I think you might want `((c-mode c++-mode) . ("clangd" ...))` where the modes are in a list.
jvillasante · 2022-10-31 22:29
Bingo! Thank you very much! Changing the `eglot-server-programs` to the following seems to work now: ``` (with-eval-after-load 'eglot (add-to-list 'eglot-server-programs '((c-mode c++-mode) . ("clangd" "-j=8" "--log=error" "--malloc-trim" "--background-index" "--clang-tidy" "--cross-file-rename" "--completion-style=detailed" "--pch-storage=memory" "--header-insertion=never" "--header-insertion-decorators=0")))) ```