vscode-clangd
vscode-clangd copied to clipboard
Editor reload is required to make changes in compile_command.json take effect for already-open files
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)
Related: https://github.com/clangd/clangd/issues/83
Another related issue is #6.
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.
Some relevant discussion at https://github.com/clangd/vscode-clangd/issues/300#issuecomment-1049149308