This is a minimal stm32 project based on libopencm3 library.
The problem is clangd language server in neovim, does not detect definitions in some header files and throws errors. For example if you open the header file libopencm3/stm32/dma.h
which is included in main.c
, the line #include <libopencm3/stm32/f4/dma.h>
should be active due to definition of STM32F4
in makefile. Now if you open libopencm3/stm32/f4/dma.h
here is the file contents:
#ifndef LIBOPENCM3_DMA_H
#define LIBOPENCM3_DMA_H
#include <libopencm3/stm32/common/dma_common_f24.h>
#endif
Two diagnostic messages are displayed in this file. In first line:
Too many errors emitted, stopping now
and in the #include ...
line:
In included file: unknown type name BEGIN_DECLS
And int the dma_common_f24.h
file, the lines between #ifdef LIBOPENCM3_DMA_H
and #else
are grayed out, and the warning message in the bottom line is active despite definition of the LIBOPENCM3_DMA_H
in the dma.h
file.
The project builds and runs with no errors or warnings. But the code completion and go-to-definition (in this case, for dma function) doesn't work due to the LSP issue.
Based on this question I tried adding include paths to the .clangd
file in my project root directory, but that didn't solve the problem.
For building the project using arm-none-eabi-gcc:
git clone https://github.com/mehdi-norouzi/clangd-test.git
cd clangd-test
git submodule init && git submodule update
cd libopencm3
make TARGET=stm32/f4
cd ..
make
compile_commands.json
will be in the build
directory. Also you may have to change the --sysroot
path in .clangd
file based on the directory of the toolchain.
PS: Vscode and intellisense have no LSP errors in this project and completion and go-to-definition are functioning correctly.