vscode-clangd icon indicating copy to clipboard operation
vscode-clangd copied to clipboard

Editor reload is required to make changes in compile_command.json take effect for already-open files

Open dan1994 opened this issue 5 years ago • 4 comments

When regenerating compile_commands.json, changes don't take effect until editor reload.

Minimal example create a main.cpp file with the content:

void foo(int a) {}

int main() {
    foo(0);
    return 0;
}

Create a compile_commands.json with the following content (replace directory appropriately):

[
    {
        "arguments": [
            "g++",
            "-c",
            "-Wall",
            "-Wextra",
            "-Werror",
            "-o",
            "main.o",
            "main.cpp"
        ],
        "directory": <path/to/directory>,
        "file": "main.cpp"
    }
]

You should see an error for an unused parameter. Now remove the warning flags so that compile_commands.json looks like this:

[
    {
        "arguments": [
            "g++",
            "-c",
            "-o",
            "main.o",
            "main.cpp"
        ],
        "directory": <path/to/directory>,
        "file": "main.cpp"
    }
]

The error still appears, although the file compiles. It disappears only after reloading vscode.

System information Clangd version (from the log, or clangd --version): 10.0.0-4ubuntu1 clangd extension version: v0.1.6 Operating system: Windows + WSL2 (Ubuntu 20.04)

dan1994 avatar Jun 12 '20 15:06 dan1994

Related: https://github.com/clangd/clangd/issues/83

HighCommander4 avatar Jun 12 '20 15:06 HighCommander4

Another related issue is #6.

i-ky avatar Jun 15 '20 11:06 i-ky

Is there anything missing to make this work? When I change a define (for instance), it's usually not picked up until I close and reopen the file in VSCode. So the file watching part and so on seems to work, but the text editor (highlighting) side of things apparently doesn't pick up changes automatically.

grigorig avatar Sep 14 '22 11:09 grigorig

Some relevant discussion at https://github.com/clangd/vscode-clangd/issues/300#issuecomment-1049149308

HighCommander4 avatar Sep 16 '22 08:09 HighCommander4