-
Notifications
You must be signed in to change notification settings - Fork 0
How To Setup clangd
Using clangd will compile the kernel in the background and show all errors and warning, similar to ElixirLS. It's much easier to find and fix bugs while still in the editor, as the alternative is to build the kernel with buildroot, then examine the output for files and line numbers for editing from the separate console window.
Install in WSL the clangd extension:
The configuration for clangd is stored in the linux.code-workspace file, so be sure to use the workspace when working on the kernel. Note the linux.code-workspace file is for WSL, if running Linux use the linux-linux.code-workspace file instead. There is also some configuration stored in the .clangd file at the root, for now this is used to exclude some gcc warnings that clang doesn't recognize.
First you must be able to cross-compile the kernel, see the wiki page. Then use bear to generate the compile_commands.json file that is used by the clangd extension.
If bear is not installed, install it with:
sudo apt update
sudo apt install -y bear
Then create the compile-commands.json file:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- clean
bear -- make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all
Note the compile-commands.json and .clangd files are stored as part of the git archive, so you'll only need to regenerate on kernel updates or additions.