Skip to content

Latest commit

 

History

History
72 lines (60 loc) · 3.71 KB

C_CPP_CONFIGURATION.md

File metadata and controls

72 lines (60 loc) · 3.71 KB

For code navigation the Microsoft C/C++ Extension or Clangd extension can be used for C/C++ language support. By default, projects created with ESP-IDF: Create Project from Extension Template or ESP-IDF: Show Examples Projects include a template for Microsoft C/C++ extension c_cpp_properties.json configuration file and doesn't need to be configured.

Run ESP-IDF: Run idf.py reconfigure task to generate the compile_commands.json file so language support works.

Configuration of c_cpp_properties.json File

The C/C++ Extension can be used to provide C and C++ syntax highlight, code navigation and Go to declaration/definition within C and C++ files. The default configuration file is located in {PROJECT_DIR}/.vscode/c_cpp_properties.json and can be generated by using ESP-IDF: Create Project from Extension Template command or using the ESP-IDF: Add .vscode Configuration Folder command.

Why configure this file?

To enable Code Navigation, auto-complete and other language support features on ESP-IDF source files on Visual Studio Code. Please take a look at C/C++ Configurations for more detail about c_cpp_properties.json configuration fields.

Default Configuration with compile_commands.json

For the default configuration, you must build your project beforehand in order to generate ${workspaceFolder}/build/compile_commands.json (where ${workspaceFolder} is your project directory). This file will then be used to resolve your C/C++ headers.

{
  "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}"
        ]
      }
    }
  ],
  "version": 4
}

NOTE: When you create a project using the extension commands such as Show Examples Projects, New Project, Create Project from Extension Template or you add the configuration files to an existing project using the Add .vscode Configuration Folder, this file is created with the compilerPath of the configured toolchain for your current IDF_TARGET in sdkconfig.

Recursive search configuration

With this configuration, the IntelliSense engine of the C/C++ extension will include all header files found by performing a recursive search of the ${config:idf.espIdfPath}/components folder. For this configuration to work, you need to set you C/C++ Extension IntelliSense engine to Tag Parser by using C_Cpp.intelliSenseEngine": "Tag Parser" in your settings.json and remove the "compileCommands": "${workspaceFolder}/build/compile_commands.json" property from the c_cpp_properties.json. Example:

{
  "configurations": [
    {
      "name": "ESP-IDF",
      "compilerPath": "/path/to/toolchain-gcc",
      "includePath": [
        "${config:idf.espIdfPath}/components/**",
        "${config:idf.espIdfPathWin}/components/**",
        "${workspaceFolder}/**"
      ],
      "browse": {
        "path": [
          "${config:idf.espIdfPath}/components",
          "${config:idf.espIdfPathWin}/components",
          "${workspaceFolder}"
        ]
      }
    }
  ],
  "version": 4
}