reasonml-editor / vscode-reasonml

OCaml & Reason support for Visual Studio Code
Apache License 2.0
490 stars 62 forks source link

Syntax highlighting gets confused in a few corner cases #157

Open yminsky opened 6 years ago

yminsky commented 6 years ago

A few examples of the syntax highlighting not working quite right.

In the following example, you can see that begin/end are not highlighted as keywords --- they should ideally be in the same color as match and with.

image

Two issues are on display here: first, the first let is unhighlighted, presumably due to the [%map_open annotation. The second is that the "and" looks different from the "let", and presumably should be in the same syntactic class, since it's a keyword in the same construct.

image

yminsky commented 6 years ago

Similarly, struct and end are not marked as keywords, but probably should be. image

ghost commented 6 years ago

Thanks for the report.

Two of these are definitely bugs that I can fix:

The others are "intentional" although I agree they look less than ideal with that theme.

The reason that some of the keywords begin, end, and and are highlighted differently from the others is because I've tried to optimize colorization for readability (via contrast) rather than the strict syntactic category of the token. I realize this is a somewhat controversial choice but there is at least a rationale behind it.

Here is what those snippets look like with the Dark+ theme that ships with VS Code:

screen shot 2018-01-14 at 15 30 04

The reason there's sometimes a lack of consistency between the themes has to do with the rather unfortunate and haphazard manner in which TextMate themes have evolved. There are really no standard scopes for highlighting different parts of the syntax.

There are some very rough conventions used for basic things like literals, strings, etc., but it's hard to rely on those. Some themes support much more fine-grained colorization than others. Some themes may provide scopes for certain syntactic constructs (sometimes even specific to a particular language) while others may not.

If you try out several different TextMate themes (especially across the different editors that support them) you'll probably notice a lot of little inconsistencies like this. I do try to account for the inconsistencies by tuning the highlighter with a number of popular themes and that works okay but the results are not perfect.

However, I will try to adjust the highlighting with Dracula for begin and end and see if there are some other areas I can improve.

For what it's worth, I expect that the Dark+ theme will usually look the best out of the available options because it tends to be more complete and has a wider color palette.

yminsky commented 6 years ago

I tried switching to Dark+, and I don't think it really helps. A few thoughts:

As a general matter, I think font coloring schemes often lean too far in the candy-striper direction, with more colors than the reader's mind can easily grasp. I think leaning a bit minimalistic will lead to a more usable result.

ghost commented 6 years ago

I have fixed the [%map_open let issue in release 1.0.21. I am considering the other changes but they require some subtle refactoring of the grammar and I haven't yet had a chance to go through and make those changes and ensure they don't lead to more bugs.