I am trying to configure lsp-mode
with clangd
using emacs 28.1 (compiled from source), and encounter two problems that I do not manage to solve:
When I start lsp-mode
with M-x lsp
, it becomes active and is 'there'. What am I missing in the configuration ?
UPDATE: solved by adding (add-hook 'prog-mode-hook 'lsp-deferred)
(use-package lsp-mode
:commands (lsp lsp-deferred)
:hook ((c-mode-hook . lsp-deferred)
(c++-mode-hook . lsp-deferred)
(lsp-mode . lsp-enable-which-key-integration))
:init
(setq lsp-keymap-prefix "C-c l")
:config
(lsp-enable-which-key-integration t))
Second, clangd
does not find include files, for example <vector>
. The message I get is 'vector' file not found [pp file not found]
.
In *clangd::stderr*
, I see:
I[14:46:03.318] Ubuntu clangd version 12.0.0-3ubuntu1~20.04.5
I[14:46:03.318] PID: 73004
I[14:46:03.318] Working directory: xxxx
I[14:46:03.318] argv[0]: /usr/bin/clangd-12
I[14:46:03.318] argv[1]: --header-insertion-decorators=0
I[14:46:03.318] Starting LSP over stdin/stdout
I[14:46:03.318] <-- initialize(1)
I[14:46:03.319] --> reply:initialize(1) 0 ms
I[14:46:03.380] <-- initialized
I[14:46:03.381] <-- textDocument/didOpen
I[14:46:03.381] Loaded compilation database from /xxx/src/compile_commands.json
I[14:46:03.381] --> window/workDoneProgress/create(0)
I[14:46:03.381] Enqueueing 16 commands for indexing
I[14:46:03.382] ASTWorker building file /xxx/xxx.cpp version 0 with command
[/xxx/build]
/usr/bin/c++ --driver-mode=g++ -DBOOST_ALL_NO_LIB -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -isystem /usr/local/include/opencv4 -pthread -std=gnu++17 -o CMakeFiles/xxx.dir/src/xxx.cpp.o -c /xxx/src/xxx.cpp -fsyntax-only -resource-dir=/usr/lib/llvm-12/lib/clang/12.0.0
My project is built using cmake, and the generated compile_commands.json
file in the source directory seems to be found by clangd
. Yet, it does not find the right headers (which are installed and visible to g++, the project compiles just fine when I run make).
What am I missing here?