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

Feature request: Better C# syntax colorizer #674

Closed
aeschli opened this issue Aug 17, 2016 · 16 comments
Closed

Feature request: Better C# syntax colorizer #674

aeschli opened this issue Aug 17, 2016 · 16 comments

Comments

@aeschli
Copy link
Contributor

aeschli commented Aug 17, 2016

From @nfantone on August 17, 2016 14:57

On latest Insiders (1.5.0-55168276e4c0b6ec2404ac20af04eeed5f5b1000), C# syntax highlighting look very bland.

screen shot 2016-08-17 at 11 39 26 am

As you can see, almost 70% of the text is just plain white, with only a few keyword being blue. Tried different themes as well, and all of them colorize the same bits leaving what was white-ish in the default theme intact.

Am I doing something wrong? Is there an extension of sorts for enhancing this? I am new to C# in general, so perhaps this is to be expected? Or are there plans to support better syntax highlighting in the future?

Copied from original issue: microsoft/vscode#10619

@johanneskopf
Copy link

Same here with the latest 1.5.0 insider.
"Vector3", "Input" and "Screen" for example in my picture should definitely be colorized.

csharp_syntaxhighlighting

@DustinCampbell
Copy link
Member

@aeschli: Note that this is a request for property semantic type colorization, which I do not believe is possible with VS Code today, since it relies on a syntactic grammar. Please let me know if I'm incorrect about that.

@aeschli
Copy link
Contributor Author

aeschli commented Aug 18, 2016

@DustinCampbell You are correct, we only have syntax highlighting through text mate grammars. Some grammars go quite far as to also parse statements and expressions, but depending on the complexity of the language this is not feasible.

@cwe1ss
Copy link

cwe1ss commented Sep 9, 2016

@nfantone @aeschli seems like this specific screenshot is from using the "Dark" theme instead of "Dark+" (which has nicer highlighting), isn't it?

Themes can be changed in the command palette by typing "Preferences: Color Theme"

@nfantone
Copy link

nfantone commented Sep 9, 2016

@cwe1ss While it's still has plenty of room for improvement, since 1.4.0 release, colorizer greatly improved. That screenshot was taken almost a month ago, now. Not entirely sure, but it should have been taken using 1.3.0.

However, I do remember that switching themes at that moment did absolutely nothing but change the colors of what was already colorized in the shown theme.

Currently, it looks something like this (using Dark+):

screen shot 2016-09-09 at 2 56 44 pm

It'd be great if classes whose static members are being accessed would be somewhat emphasized and not left completely white (like that Random.Range call). As an example, take a look at what Visual Studio does.

@ivanz
Copy link
Contributor

ivanz commented Sep 23, 2016

Found this feature request in VSCode for exposing a way to plug-in programmatic (semantic) highlighting: microsoft/vscode#585

Until that's implemented we can only do syntax highlighting based on regular expressions, which can do only so much.

@DustinCampbell
Copy link
Member

Thanks @ivanz. I went ahead and commented on that issue as well.

@nfantone
Copy link

@DustinCampbell One thing I can't quite get my head around is why we need semantic knowledge of an instruction to change the color of Customer in something like this: Customer.Find(). I know next to nothing about textmate, but it sure seems like something incredibly simple to implement with a regex.

The only complication I can think of is if someones uses PascalCase to name their variables or does not with classes names. But, then again, those people deserve not to have proper syntax highlighting.

If you assume some kind of coding standard, you can begin to cover a very wide range of cases without semantic shenanigans.

@DustinCampbell
Copy link
Member

@nfantone: It's not shenanigans. Casing isn't enough to even make an educated guess. Without semantically knowing what Customer is, we have no why of knowing whether its a class, a property, a public field, etc.

Note that we actually already have all of this information with OmniSharp. We have all the same information that is used to colorize Visual Studio. We just need a way to present that information in VS Code.

@nfantone
Copy link

@DustinCampbell You are right. I know it's not "shenanigans". Bad wording, sorry. I disagree with this, tough:

Casing isn't enough to even make an educated guess.

Frankly, I believe it's more than enough. It won't be an exact match, but it'll sure be educated.

My point was (is) why aren't we colorizing those terms anyway? Why is the alternative (mostly white text) preferable? Maybe I'm alone with this opinion here, but I'd take having Customer in Customer.Find() being of a different color than Find() any day - regardless of it being a static reference, a local variable or a class attribute.

Just for reference, that is what the Javascript syntax highlighter in, say, ST3 does. See below.

screen shot 2016-09-25 at 8 49 33 pm

Both Object and Customer are colorized different than their members.

@DustinCampbell
Copy link
Member

We're definitely accepting pull requests. However, as we already have exactly the information to colorize, we're not willing to spend cycles adding heuristics to the reg-ex based grammar to make it look right some of the time.

JavaScript is not really a fair comparison as the standard for casing is pretty different. In C#, we'd get it wrong a lot more often.

@nfantone
Copy link

nfantone commented Sep 26, 2016

Ok, fair enough. Understood.

We'll just wait until there's a proper way to output the information you already have in the editor. Thanks!

@kkukshtel
Copy link

kkukshtel commented Dec 9, 2016

Just want to comment on this issue as well and still state that it's a headache on VSCode. Not sure if anything has changed, but the highlighting available is poor at best across almost all themes.

@DustinCampbell - if you have any pointers about where to start to make this a community effort it would be much appreciated.

highlight

@DustinCampbell
Copy link
Member

@kkukshtel: The regular expressions used to colorize code are on this repo and we're definitely accepted pull requests. The problem (I think) is that you're looking for colorization that requires semantic information (i.e. is this identifier a class, an interface, a property, etc.?), which can't be determine via regular expressions. We already have all of that information with OmniSharp via Roslyn, but what is missing is an API to add it to VS Code. This issue is tracking a VS Code API that would allow us to take advantage of that information and provide better colorization (identical to Visual Studio) is here: microsoft/vscode#585. cc @chrisdias, @jrieken

@DustinCampbell DustinCampbell added this to the 1.7 milestone Jan 10, 2017
@DustinCampbell
Copy link
Member

This should all look much in the next release:

image

image

image

@kkukshtel
Copy link

😍😍😍😍😍😍😍😍

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

7 participants