kang
kang

Reputation: 37

How to disable C# extension on VS Code changing the color?

After I installed and enabled C# extension on VS Code, my text color turned from this:

color_theme-1

to this:

color_theme-2

How can I keep the C# extension enabled, but not change the text color?

Thanks!

Upvotes: 2

Views: 1391

Answers (4)

Alexandra Moisi
Alexandra Moisi

Reputation: 1

First, I tried disabling the C# semantic highlighting and enabling the editor but it didn't work. exactly the opposite worked for me. this is my settings json:

{
    "csharp.semanticHighlighting.enabled": true,
    "workbench.settings.applyToAllProfiles": [
        "csharp.semanticHighlighting.enabled"
    ],
    "editor.semanticHighlighting.enabled": false,
    "omnisharp.enableEditorConfigSupport": true,
    "csharp.format.enable": true,
    "razor.format.enable": true,
    "omnisharp.useEditorFormattingSettings": true,
    
    }
    

Upvotes: 0

Berkay Olce
Berkay Olce

Reputation: 11

"First, press Ctrl + , and type "semantic" in the search bar, then set both the "Editor › Semantic Highlighting: Enabled" and "Csharp › Semantic Highlighting: Enabled" options to "false." This fixed the issue for me."

Upvotes: 1

kang
kang

Reputation: 37

Thanks for the detailed explanation!
I eventually figured out by disabling Semantic Highlighting. What I did:

  1. Press Ctrl+Shift+P
  2. Type in SemanticHighlighting
  3. Uncheck Csharp > Semantic Highlighting

The problem seems like C# extension mistakenly interpret the syntax so it gives the wrong colors. When I was checking the token with C# extension DISABLED, it shows enter image description here

but after I ENABLED the C# extension, it became

enter image description here

so I guess that it might mistakenly interprets the syntax.

Upvotes: 2

carlfriedrich
carlfriedrich

Reputation: 4093

Probably the C# extension adds new scopes, which were not known to VS Code before, and these are now rendered differently (i.e. more exact, better respecting your configured theme). You can check that by running the scope inspector: press Ctrl+Shift+P to bring up the command palette and run the Developer: Inspect Editor Tokens and Scopes command while the cursor is on one of the tokens with changing color.

enter image description here

If you really want to change colours, you can customize your theme in VS code by adding something like the following to your JSON configuration:

"workbench.colorCustomizations": {
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": [
                    "comment.block.js",
                ],
                "settings": {
                    "foreground": "#FF0000",
                }
            },
        ]
    }
}

So what you would have to do:

  1. Disable the C# Extension
  2. Use the scope inspector to find out all color values that you would like to keep and write them down somewhere
  3. Enable the C# Extension again
  4. Use the scope inspector to find out all scopes of tokens which changed their color
  5. Add a textmate rule for each scope with the previous colour to your settings

Upvotes: 0

Related Questions