Next, configure your project. Go to View
> Command Palette
and enter ESP-IDF: SDK Configuration Editor
to adjust ESP-IDF project settings.
C and C++ Code Navigation and Syntax Highlighting
Note
C and C++ code navigation is automatically configured if you create the project as described in Configure Your Project. Those commands generate the {PROJECT_DIRECTORY_PATH}/.vscode/c_cpp_properties.json
file.
For code navigation and C/C++ syntax highlighting, you can use Microsoft C/C++ extension, LLVM clangd extension, or any other preferred extension.
Usually C/C++ language extensions rely on a file called compile_commands.json
, which is located in your project build directory. You can generate this file using the ESP-IDF: Run idf.py reconfigure task
.
For LLVM clangd extension, the user can use the ESP-IDF: Configure project for ESP-Clang
to configure this extension argument.
The command will search for esp-clang
in the configured ESP-IDF setup, the build directory from idf.buildPath
(idf.buildPathWin
in Windows) and the GCC toolchain path from current IDF_TARGET
and configured ESP-IDF setup and use these paths to configure clang path and arguments.
The result looks like this:
{
"clangd.path": "/Users/user/.espressif/tools/esp-clang/esp-18.1.2_20240912/esp-clang/bin/clangd",
"clangd.arguments": [
"--background-index",
"--query-driver=/Users/user/.espressif/tools/xtensa-esp-elf/esp-14.2.0_20241119/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc",
"--compile-commands-dir=/path/to/esp-idf-project/build"
]
}
For Microsoft C/C++ extension, a configuration file is located at {PROJECT_DIRECTORY_PATH}/.vscode/c_cpp_properties.json
. This file can be generated by creating a project using ESP-IDF: New Project
, ESP-IDF: Show Example Projects
command, or by using the ESP-IDF: Add .vscode Configuration Folder
command on an existing ESP-IDF projects.
The file structure is as follows:
{
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "/path/to/toolchain-gcc",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"includePath": [
"${config:idf.espIdfPath}/components",
"${config:idf.espIdfPathWin}/components/",
"${workspaceFolder}/"
],
"browse": {
"path": [
"${config:idf.espIdfPath}/components",
"${config:idf.espIdfPathWin}/components",
"${workspaceFolder}"
]
}
}
]
}
If compile_commands.json
is not defined, Microsoft C/C++ extension will browse the provided ESP-IDF path to resolve code navigation.