How to make LSP to be aware of project context (c++)

Apologies if description is unclear, I’ll try to describe my problem best way i can.
I use a tool to build my c++ project for me called cmake.

From my root project directory i have all my libraries stored in ./libraries/“lib_folder_name”

My source code stored in ./source/

and my build and binary files in ./build/

The problem is while editing source code files kak-lsp is is not aware of project structure
and using “#include <lib_name/header>” and all functions used by that library are interpreted as an error by kak-lsp.

  • ‘lib/name’ file not found

The only “solution” is to use "#include “…/libraries/path/to/header/file” which works with kak-lsp.

The C++ language servers read a file called compile_commands.json in the project root.
See clangd’s Getting started for how to set that up. For CMake you can use this:

cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ..
cd .. && ln -s build/compile_commands.json .

(this will work for any editor that uses clangd)


Excellent, thank you.
I thought i need to symlink compile_commands.json to project root or source code project root also, but as it turns out, this is unnecessary. This works without symlink.