Automatically grey out disabled code by Preprocessor Directives (#define)

gonzalo
Posts: 3
Joined: Fri Jan 21, 2022 12:02 pm

Automatically grey out disabled code by Preprocessor Directives (#define)

Postby gonzalo » Fri Apr 21, 2023 4:59 pm

Hello. I'm in the transition of porting my whole project from Platformio+Arduino to IDF VS Code Extension+IDF+Arduino

I miss a feature that I'm not sure if it's Platformio specific. In my project I configure how the code is compiled enabling and disabling #defines (preprocessor directives).

Previously when I commented out a #define VSCode automatically greyed out the code that was disabled by a preprocessor directive.

Now with this change to plain IDF+Arduino As A Component (using the VS Code extension), that functionality is lost. The IDE is not dinamically evaluating the preprocessor directives nor greying out code.

How can I recover that functionaliy? I can provide pictured if I wasn't enough clear with the explanation.

gonzalo
Posts: 3
Joined: Fri Jan 21, 2022 12:02 pm

Re: Automatically grey out disabled code by Preprocessor Directives (#define)

Postby gonzalo » Mon Apr 24, 2023 5:44 pm

I've found the issue. Intellisense is configured differently in the VSCode IDF Extension default templeate than in Platformio.

Adding "compileCommands": "${workspaceFolder}/build/compile_commands.json" to .vscode/c_cpp_properties.json and changing C_Cpp.intelliSenseEngine to default in .vscode/settings.json did the trick!

Note: You have to build for this to work because the file compile_commands.json is generated during compilation.

Code: Select all

{
    "configurations": [
        {
            "name": "ESP-IDF",
            "compilerPath": "c:\\Espressif\\tools\\xtensa-esp32-elf\\esp-2021r2-patch5-8.4.0\\xtensa-esp32-elf\\bin\\xtensa-esp32-elf-gcc.exe",
            "includePath": [
                "${config:idf.espIdfPath}/components/**",
                "${config:idf.espIdfPathWin}/components/**",
                "${config:idf.espAdfPath}/components/**",
                "${config:idf.espAdfPathWin}/components/**",
                "${workspaceFolder}/**"
            ],
            "browse": {
                "path": [
                    "${config:idf.espIdfPath}/components",
                    "${config:idf.espIdfPathWin}/components",
                    "${config:idf.espAdfPath}/components/**",
                    "${config:idf.espAdfPathWin}/components/**",
                    "${workspaceFolder}"
                ],
                "limitSymbolsToIncludedHeaders": false
            },
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
        }
    ],
    "version": 4
}

Code: Select all

{
    "C_Cpp.intelliSenseEngine": "default",
    "idf.adapterTargetName": "esp32",
    "idf.customExtraPaths": "c:\\Espressif\\tools\\xtensa-esp-elf-gdb\\11.2_20220823\\xtensa-esp-elf-gdb\\bin;c:\\Espressif\\tools\\riscv32-esp-elf-gdb\\11.2_20220823\\riscv32-esp-elf-gdb\\bin;c:\\Espressif\\tools\\xtensa-esp32-elf\\esp-2021r2-patch5-8.4.0\\xtensa-esp32-elf\\bin;c:\\Espressif\\tools\\xtensa-esp32s2-elf\\esp-2021r2-patch5-8.4.0\\xtensa-esp32s2-elf\\bin;c:\\Espressif\\tools\\xtensa-esp32s3-elf\\esp-2021r2-patch5-8.4.0\\xtensa-esp32s3-elf\\bin;c:\\Espressif\\tools\\riscv32-esp-elf\\esp-2021r2-patch5-8.4.0\\riscv32-esp-elf\\bin;c:\\Espressif\\tools\\esp32ulp-elf\\2.35_20220830\\esp32ulp-elf\\bin;c:\\Espressif\\tools\\cmake\\3.23.1\\bin;c:\\Espressif\\tools\\openocd-esp32\\v0.11.0-esp32-20221026\\openocd-esp32\\bin;c:\\Espressif\\tools\\ninja\\1.10.2;c:\\Espressif\\tools\\idf-exe\\1.0.3;c:\\Espressif\\tools\\ccache\\4.3\\ccache-4.3-windows-64;c:\\Espressif\\tools\\dfu-util\\0.9\\dfu-util-0.9-win64",
    "idf.customExtraVars": {
        "OPENOCD_SCRIPTS": "c:\\Espressif\\tools\\openocd-esp32\\v0.11.0-esp32-20221026/openocd-esp32/share/openocd/scripts",
        "IDF_CCACHE_ENABLE": "1"
    },
    "idf.espIdfPathWin": "c:\\Espressif\\esp-idf",
    "idf.openOcdConfigs": [
        "interface/ftdi/esp32_devkitj_v1.cfg",
        "target/esp32.cfg"
    ],
    "idf.portWin": "COM3",
    "idf.pythonBinPathWin": "c:\\Espressif\\python_env\\idf4.4_py3.8_env\\Scripts\\python.exe",
    "idf.toolsPathWin": "c:\\Espressif",
    "idf.flashType": "UART",
    "files.associations": {
        "thread": "cpp",
        "random": "cpp",
        "*.ipp": "cpp",
        "*.tcc": "cpp",
        "*.tpp": "cpp"
    }
}

Who is online

Users browsing this forum: No registered users and 48 guests