Solved: "Go to definition" in source files outside the workspace
Intro
When I'm using the "STM32CubeIDE for Visual Studio Code" extension, I often want to edit C source files outside of my workspace, which are listed in my CMakeLists.txt and get compiled into the firmware just like any other C file. Unfortunately, with the default setup, the language server (clangd) cannot find some of the headers I include, and it doesn't know the right compilation options, so intelligent features like inlay hints (red squiqqlies) and the "Go to definition" command do not work properly.
The ST extension attempts to communicate this kind of information to the language server by putting a ".clangd" file at the root of my workspace folder which has a line in it like "CompilationDatabase: build_release". But clangd won't consider that file when looking at source files outside of the workspace.
Motivation
I have multiple STM32 projects that share some common libraries, so my folder structure looks like:
lib/lib1/lib1.c
lib/lib1/lib1.h
lib/lib2/lib2.c
lib/lib2/libc2.h
project1/CMakeLists.txt
project1/CMakePresets.json
project1/src/project1.c
As far as I know, I have to set my workspace folder to "project1" meaning that all the library code is outside of the workspace. I want a good experience while editing those libraries.
Edit: Moved the solution to separate post, at the request of ST.
