Skip to content

compile_commands.json file not found if created after the initial editor load and its path contains variables #7241

Description

Type: LanguageService

Describe the bug

  • OS and Version: Ubuntu 20.04
  • VS Code Version: 1.54.3
  • C/C++ Extension Version: 1.3.0-insiders2
  • Other extensions you installed (and if the issue persists after disabling them): persists without other extensions
  • Does this issue involve using SSH remote to run the extension on a remote machine?: no

When the compile_commands.json file path includes variables like ${workspaceFolder} the file is found if it exists only during the initial editor load, but not if it was created after the editor was started.

Steps to reproduce

Make a simple program that includes a header from an external library, and set the compileCommands item in the c_cpp_properties.json file (or in more general settings) to something like ${workspaceFolder}/build/compile_commands.json. Make sure the build folder is clean and then compile the program to generate the compile_commands.json file. The include directives should still be marked with red lines indicating that the extension couldn't locate the compile_commands.json file.

Example (lib can be any available library):

main.cpp

#include "lib.hpp"

int main()
{
    lib();
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(app)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(lib REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} lib::lib)

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
        }
    ],
    "version": 4
}

Expected behavior

I expect the include paths to get resolved shortly after the compile_commands.json file is created.

Logs
-------- Diagnostics - 3/27/2021, 7:55:19 AM
Version: 1.3.0-insiders2
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [],
    "compilerPath": "/usr/bin/gcc",
    "cStandard": "gnu17",
    "cppStandard": "gnu++14",
    "intelliSenseMode": "linux-gcc-x64",
    "compileCommands": "${workspaceFolder}/build/compile_commands.json",
    "compilerArgs": [],
    "intelliSenseModeIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "compilerPathIsExplicit": true,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /home/user/source/test/app/src/main.cpp ]:
    /home/user/source/test/app/src/main.cpp
Translation Unit Configurations:
[ /home/user/source/test/app/src/main.cpp ]:
    Process ID: 12164
    Memory Usage: 10 MB
    Compiler Path: /usr/bin/gcc
    Includes:
        /usr/include/c++/9
        /usr/include/x86_64-linux-gnu/c++/9
        /usr/include/c++/9/backward
        /usr/lib/gcc/x86_64-linux-gnu/9/include
        /usr/local/include
        /usr/include/x86_64-linux-gnu
        /usr/include
    Standard Version: c++14
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --g++
        --gnu_version=90300
Total Memory Usage: 10 MB

------- Workspace parsing diagnostics -------
Number of folders and files enumerated: 3635
Number of files discovered (not excluded): 3081

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions