Since version 0.1.25 (which replaced the old behavior of highlighting regions with the default comment color) the vscode-clangd extension does not clear either background highlights or lowered opacity of inactive code before reloading the server. Background highlights or opacity are re-applied to the code (additively in case of the background highlight). Additionally, if the inactive code changed during the reload due to using a new compile_commands.json or edits to the existing one, code can be highlighted as inactive even while it is active.
As an example, consider the following C++ program:
#include <iostream>
#ifdef A
#define MESSAGE "Howdy A!"
#else
#ifdef B
#define MESSAGE "Hello B!"
#else
#error "A or B must be defined"
#endif
#endif
int main() {
std::cout << MESSAGE << std::endl;
}
and the following (handwritten for simplicity) compile_commands.json:
When loading a folder containing these two files in VSCode, vscode-clangd properly marks the inactive regions:
If we now change -DA to -DB in compile_commands.json and run clangd.restart the highlights from -DA persist:
For completeness, this also works on the "error" branch if we drop the define entirely:
This behaves similarly if the clangd.inactiveRegions.useBackgroundHighlight setings is enabled, but the highlights appear to stack, getting darker as you repeatedly reload, even without changing the compile_commands.json file.
My hunch is that this occurs because there is no code to clear the regions in the dispose method, but I'm very new to VSCode extension development so I am unsure I'm understanding the root cause properly.
Logsclangd.log
(Covers walking through the same steps as shown in the example)
System information
Clangd version (from the log, or clangd --version): 17.0.3
clangd extension version: 0.1.27-0.1.25 (tested with all 3 versions)
Operating system: Linux x86-64, using remote development through a Windows 10 machine (though I think that isn't relevant here?)
Since version 0.1.25 (which replaced the old behavior of highlighting regions with the default comment color) the
vscode-clangd
extension does not clear either background highlights or lowered opacity of inactive code before reloading the server. Background highlights or opacity are re-applied to the code (additively in case of the background highlight). Additionally, if the inactive code changed during the reload due to using a newcompile_commands.json
or edits to the existing one, code can be highlighted as inactive even while it is active.As an example, consider the following C++ program:
and the following (handwritten for simplicity)
compile_commands.json
:When loading a folder containing these two files in VSCode,
If we now change
For completeness, this also works on the "error" branch if we drop the define entirely:
![image](https://github.com/clangd/vscode-clangd/assets/31926270/537b9258-ddfd-4cf1-b7b1-2d7eec24815e)
vscode-clangd
properly marks the inactive regions:-DA
to-DB
incompile_commands.json
and runclangd.restart
the highlights from-DA
persist:This behaves similarly if the
clangd.inactiveRegions.useBackgroundHighlight
setings is enabled, but the highlights appear to stack, getting darker as you repeatedly reload, even without changing thecompile_commands.json
file.My hunch is that this occurs because there is no code to clear the regions in the dispose method, but I'm very new to VSCode extension development so I am unsure I'm understanding the root cause properly.
Logs clangd.log (Covers walking through the same steps as shown in the example)
System information Clangd version (from the log, or
clangd --version
): 17.0.3 clangd extension version: 0.1.27-0.1.25 (tested with all 3 versions) Operating system: Linux x86-64, using remote development through a Windows 10 machine (though I think that isn't relevant here?)