microsoft / language-server-protocol

Defines a common protocol for language servers.
https://microsoft.github.io/language-server-protocol/
Creative Commons Attribution 4.0 International
11.29k stars 803 forks source link

Add token/symbol for inactive code #1938

Open RobbyCBennett opened 6 months ago

RobbyCBennett commented 6 months ago

Currently, extensions have an odd way of dimming or coloring inactive code. They add non-standard a CSS class and the class dims the code. The opacity and colors are configured in the extension settings instead of in the standard place for colors in VS Code: tokenColorCustomizations: textMateRules.

// Here's what this may look like in VS Code if the user wants to configure it.
"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
            "scope": "inactive",
            "settings": {
                "opacity": 0.5
            }
        }
    ]
},

Here are some example of how this works already.

HighCommander4 commented 4 months ago

In clangd, we initially implemented highlighting of inactive code as a custom semantic token type, but we found this approach to be limiting in a couple of ways:

  1. It did not allow for whole-line styling of the inactive region, such as a greyed-out background color (example rendering below).
  2. It stomped on foreground colors provided by the client-side coloring engine in the inactive region. (At least for semantic tokens, "editor.semanticTokenColorCustomizations" did not allow specifying a style like "opacity" which combines with foreground colors.)

We ended up using a custom protocol extension for the server to tell the client about inactive code regions. A standard version would definitely be nice (but I'm not sure that semantic tokens are the best thing to build on).

vscode-clangd-inactive

DanTup commented 2 months ago

Dart uses a Diagnostic with the DiagnosticTag.Unnecessary tag to grey the text out:

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticTag

I don't know if you can do this without a visible diagnostic though (in VS Code you might be able to use the "Hint" diagnostic which I think creates a much smaller squiggle, but I'm not sure if you can avoid it entirely).