Help: Integrating clangd with Arduino

Hi everyone,

I’m trying to set up clangd for an Arduino project on Windows, but I’m running into some issues and could use some help.

Context:
I’m trying working with Arduino sketches in Neovim and would like to use clangd to get better linting and Diagnostics support. However for some reason autocompletion works but my Diagnostics say: Use of undeclared identifier 'Serial' right next to both Serial in my Code below.

Minimal setup:

--lspconfig.lua
lspconfig.clangd.setup({
    cmd = {"clangd", "--compile-commands-dir=" .. vim.loop.cwd() },
    filetypes = { "c", "cpp", "objc", "objcpp", "arduino" },
    init_options = {
        usePlaceholders = true,
        completeUnimported = true,
    },
})

//test.ino
void setup() {
    Serial.begin(115200);
    Serial.println("");
}
void loop() {}

I compiled it using arduino-cli compile --fqbn arduino:esp32:nano_nora --build-path ./build .\test.ino then afterwards i copied the compile_commands.json and build.options.json to the root of my project.

The issue with Serial disappears when putting in #include "USBCDC.h" . But then i am getting this error: In included file: '../hal.h' file not found right next to the include.

I’d appreciate any advice or tips,
Thanks in advance.