skip to Main Content

I’m trying to build a color theme for VS Code, specifically for C/C++. Works fine, but I cannot write a textmate rule for disabled code. When I used Qt Creator, it had a specific style for disabled code:

disabled code in qtc

You can see the syntax highlighting understands that this code is disabled (or rather, the clangd tells the QTC that this code is disabled) and it applies an appropriate style for this section. Some styles slip through though, like a comment in italic, but I don’t care since the color is my main concern.

When I tried to style disabled code in VS Code, I could not find a textmate scope for it. The Developer: Inspect Editor Tokens and Scopes just tells me it’s some code, it even tries to highlight some of its portions:

disabled code in vsc

But the text is slightly faded than the rest of the code, so it somehow understands that it’s disabled, but there’s no textmate scope for it. How do I style it then? I would like it to be like in QTC, all one color. I tried using this extension, but it didn’t add any textmate scopes. I have official C/C++ extensions installed, and I use clangd instead of IntelliSense, in case it matters.

Update: This seems to be very related. If I understood this comment right, there’s now two options: background highlighting (just changes color a bit, but no control how exactly it does that) and opacity (text has some opacity and therefore fades, as I’ve mentioned above).

Update 2: Ackshually, there’s some control over clangd’s background option: it lets you change color, but this setting is hidden and only accessible as a workbench color customization: "clangd.inactiveRegions.background": "#ff0000".

2

Answers


  1. For clangd, there’s the clangd.inactiveRegions.background colour customization point.

    For cpptools, the following settings are available. Example settings.json:

    "C_Cpp.inactiveRegionForegroundColor": "#ff0000",
    "C_Cpp.inactiveRegionBackgroundColor": "#00ff00",
    "C_Cpp.inactiveRegionOpacity": 0.55,
    

    See also https://code.visualstudio.com/api/references/theme-color#color-formats.

    Login or Signup to reply.
  2. The fade out is controlled by extension providing the Unnecessary DiagnosticTag during diagnostics

    example, "editorUnnecessaryCode.opacity": "#000000c0" will render the code with 75% opacity

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search