microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.54k stars 1.56k forks source link

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

Closed yiftahw closed 1 week ago

yiftahw commented 2 weeks ago

Environment

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:
    • We can force the file watchers to be closed by reproducing the steps described in #12946.
    • fs.watch loses track of the file on Linux if file is deleted/doesn't exist. (on Linux, fs.watch tracks by inode)
    • Failed to create a file watcher by crossing the inotify limit on Linux.
  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