Skip to content

Compile commands fallback logic can miss changes when using multiple configurations with different compile_commands.json paths #12947

Description

Environment

  • OS and Version: Windows 10
  • VS Code Version: 1.95.1
  • C/C++ Extension Version: V1.22.11
  • If using SSH remote, specify OS of remote machine:

Bug Summary and Steps to Reproduce

Bug Summary:
Assuming file watchers have failed/closed, the fallback logic CppProperties.checkCompileCommands can fail to detect changes in a compile_commands.json from a different configuration index (even when later switching to that configuration index)

Steps to reproduce:
Assume the following c_cpp_properties.json (only relevant parts shown)

{
    "configurations": [
        {
            "name": "compdb1",
            "compileCommands": "${workspaceFolder}/compile_commands_1.json",
        },
        {
            "name": "compdb2",
            "compileCommands": "${workspaceFolder}/compile_commands_2.json",
        }
    ],
    "version": 4
}
  1. Assume we are using compdb1
  2. Assume file watchers failed/closed on any of the example reasons:
  3. Update compile_commands_2.json (by touching or actually compiling some CMake project)
    • Assuming file watchers are closed/failed, no event is triggered on this change.
    • checkCompileCommands() only checks the file used by the current configuration, no event is triggered on this change.
  4. Update compile_commands_1.json
    • Now, compile_commands_1.json is newer than compile_commands_2.json.
    • CppProperties.compileCommandsFileWatcherFallbackTime is assigned compile_commands_1.json's timestamp.
  5. Switch to compdb2
    • File watchers are re-created, but no event is triggered as compile_commands_2.json has changed before re-initializing the file watchers.
    • CppProperties.compileCommandsFileWatcherFallbackTime is a newer timestamp than compile_commands_2.json's timestamp, so checkCompileCommands() does not trigger an event.

Configuration and Logs

{
    "configurations": [
        {
            "name": "compdb1",
            "compileCommands": "${workspaceFolder}/compile_commands_1.json",
        },
        {
            "name": "compdb2",
            "compileCommands": "${workspaceFolder}/compile_commands_2.json",
        }
    ],
    "version": 4
}

Other Extensions

No response

Additional context

No response

Metadata

Metadata

Type

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions