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

Preprocessor Directive Coloring #2312

Closed
chrisbruno opened this issue May 16, 2018 · 8 comments
Closed

Preprocessor Directive Coloring #2312

chrisbruno opened this issue May 16, 2018 · 8 comments

Comments

@chrisbruno
Copy link

Hello. I am not sure if this is possible(or the right place to ask), but my google skills are failing me :)

I'd like to have preprocessor directives matching the color of comments when they are inactive. Here's what it looks like in visual studio:
visual_studio

and here's vs code:
vs_code

@DustinCampbell
Copy link
Member

Unfortunately, this is not possible to do with a VS Code extension. Syntax highlighting in VS Code is achieved with regular expressions, which doesn't have the context necessary to perform that level of highlighting.

@joemey
Copy link

joemey commented May 29, 2018

The vscode-ccptools has a feature like this (microsoft/vscode-cpptools#1466) maybe this can be adopted for the omnisharp plugin?

@thowthoww
Copy link

thowthoww commented Oct 10, 2019

Unfortunately, this is not possible to do with a VS Code extension. Syntax highlighting in VS Code is achieved with regular expressions, which doesn't have the context necessary to perform that level of highlighting.

Can't you parse .csproj for <DefineConstants>?

@ssoher
Copy link

ssoher commented May 31, 2020

@DustinCampbell C/C++ extension has this feature, how did they achieve it and can this be done for C#?

@JoeRobich
Copy link
Member

@ssoher If you are using the latest version of the extension, then you can enable the csharp.semanticHighlighting.enabled flag to turn on Semantic Highlighting. You can then use one of our included Visual Studio 2019 themes or define an editor theme tweak in your settings.json for your theme to set the value of the support.other.excluded scope (#808080 perhaps).

@ssoher
Copy link

ssoher commented Jun 1, 2020

@JoeRobich It works great with the included VS themes. But when I add the support.other.excluded scope to my theme it's not recognized. When I check the scope under cursor at the same point VS themes show that scope but my theme only shows source.cs. What am I missing? Thank you very much.

image

@JoeRobich
Copy link
Member

If you maintain your own Theme, you will need to add this line to your theme so that it will use the semantic highlighter.

"semanticHighlighting": true,

If you are making tweaks to a community theme, you will need to add the same to your tokenColorCustomizations - see microsoft/vscode#92740 (comment)

@ssoher
Copy link

ssoher commented Jun 1, 2020

Amazing, it works now and I've learned something, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants