2026-03-03 11:38 AM - edited 2026-03-11 2:07 PM
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.
Solved! Go to Solution.
2026-03-11 2:09 PM
Solution
Press Ctrl+Shift+P and select "Preferences: Open Workspace Settings (JSON)" to open ".vscode/settings.json". Add this line to the top-level object:
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json",Then add this string inside "stm32cube-ide-clangd.arguments":
"--compile-commands-dir=${workspaceFolder}",
At the end, your settings.json should look something like this:
{
"cmake.cmakePath": "cube-cmake",
"cmake.configureArgs": [
"-DCMAKE_COMMAND=cube-cmake"
],
"stm32cube-ide-clangd.path": "cube",
"stm32cube-ide-clangd.arguments": [
"starm-clangd",
"--query-driver=${env:CUBE_BUNDLE_PATH}/gnu-tools-for-stm32/14.3.1+st.2/bin/arm-none-eabi-gcc.exe",
"--query-driver=${env:CUBE_BUNDLE_PATH}/gnu-tools-for-stm32/14.3.1+st.2/bin/arm-none-eabi-g++.exe",
"--compile-commands-dir=${workspaceFolder}",
],
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json",
"cmake.preferredGenerators": [
"Ninja"
]
}
2026-03-05 12:35 AM
thanks for the sharing will be forwarded to the team
2026-03-11 2:09 PM
Solution
Press Ctrl+Shift+P and select "Preferences: Open Workspace Settings (JSON)" to open ".vscode/settings.json". Add this line to the top-level object:
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json",Then add this string inside "stm32cube-ide-clangd.arguments":
"--compile-commands-dir=${workspaceFolder}",
At the end, your settings.json should look something like this:
{
"cmake.cmakePath": "cube-cmake",
"cmake.configureArgs": [
"-DCMAKE_COMMAND=cube-cmake"
],
"stm32cube-ide-clangd.path": "cube",
"stm32cube-ide-clangd.arguments": [
"starm-clangd",
"--query-driver=${env:CUBE_BUNDLE_PATH}/gnu-tools-for-stm32/14.3.1+st.2/bin/arm-none-eabi-gcc.exe",
"--query-driver=${env:CUBE_BUNDLE_PATH}/gnu-tools-for-stm32/14.3.1+st.2/bin/arm-none-eabi-g++.exe",
"--compile-commands-dir=${workspaceFolder}",
],
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json",
"cmake.preferredGenerators": [
"Ninja"
]
}