Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inactive Region Highlights Persist Through clangd.restart #600

Closed
Baricus opened this issue Mar 19, 2024 · 1 comment
Closed

Inactive Region Highlights Persist Through clangd.restart #600

Baricus opened this issue Mar 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Baricus
Copy link
Contributor

Baricus commented Mar 19, 2024

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:

[
    {
        "arguments": [
            "/usr/bin/g++",
            "-DA",
            "main.cpp"
        ],
        "directory": "/path/to/folder/containing/both/files/",
        "file": "main.cpp",
        "output": "a.out"
    }
]

When loading a folder containing these two files in VSCode, vscode-clangd properly marks the inactive regions:
image
If we now change -DA to -DB in compile_commands.json and run clangd.restart the highlights from -DA persist:
image
For completeness, this also works on the "error" branch if we drop the define entirely:
image

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.

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?)

@Baricus Baricus added the bug Something isn't working label Mar 19, 2024
@HighCommander4
Copy link
Contributor

Thanks for the report. I've noticed this as well.

A workaround until the bug is fixed is to close and reopen the affected source file in the editor.

Baricus added a commit to Baricus/vscode-clangd that referenced this issue Mar 23, 2024
Disposes of the decoration when the InactiveRegionsFeature
is itself disposed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants