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

Support for Semantic highlighting for Java? #19

Closed
ronakg opened this issue Apr 30, 2020 · 13 comments
Closed

Support for Semantic highlighting for Java? #19

ronakg opened this issue Apr 30, 2020 · 13 comments

Comments

@ronakg
Copy link
Contributor

ronakg commented Apr 30, 2020

Hi,

Is there any plan for supporting Semantic highlighting for Java? vscode-java extension provides token rules that can be used by themes to highlight different variables based on their semantics.

https://github.com/redhat-developer/vscode-java/wiki/Semantic-Highlighting

@sainnhe
Copy link
Owner

sainnhe commented Apr 30, 2020

Thanks for your suggestion, I don't even know this feature until you said it.

I'll add support for the semantic highlighting in these days.

@sainnhe
Copy link
Owner

sainnhe commented May 1, 2020

I tried semantic highlighting, it works very well in typescript and javascript, but I can't figure out how to enable it in java and C++.

You can try to press Ctrl+Shift+P to open command panel and search for "Inspect Editor Tokens and Scopes". If the semantic highlighting of java is successfully enabled, then you can see a new section that shows semantic token type.

Screenshot_20200501_210532

This section does not appear when I open a java file(nor C++ file).

@ronakg
Copy link
Contributor Author

ronakg commented May 1, 2020

I do see this dialog for java files. Do you have semantic highlighting enabled for java?

Screen Shot 2020-05-01 at 1 51 00 PM

Edit: You're right. I don't see the semantic token type section either.

@ronakg
Copy link
Contributor Author

ronakg commented May 1, 2020

I was able to enable it using this setting:

    "editor.tokenColorCustomizations": {
        "[Gruvbox Material Dark]": {
            "semanticHighlighting": true
        }
    }

Found this info from here - https://github.com/microsoft/vscode/wiki/Semantic-Highlighting-Overview#which-themes-offer-semantic-highlighting

This changed highlighting a lot and I didn't like it. Too much green and yellow. So I turned it off for now.

@sainnhe
Copy link
Owner

sainnhe commented May 1, 2020

That's exactly why I'm going to optimize these file types 671033f.

I added a new option to determine whether to enable semantic highlighting which is true by default, maybe I should set it to false by default.

@ronakg
Copy link
Contributor Author

ronakg commented May 2, 2020

I think you should not add one more flag to enable semantic highlighting in the theme. There are already 2 flags, one at editor level and one at the language level. You should check if you can provide semantic highlighting for the current language and provide highlights based on that.

Just my 2 cents.

@sainnhe
Copy link
Owner

sainnhe commented May 2, 2020

Thanks for your suggestion. To be honest, I have carefully thought about this question previously, because there're already many options and too many options may confuse users.

My conclusion is that it's necessary to add an option to enable or disable semantic highlighting, because there're some potential problems in this feature.

One of them is what you have mentioned above: the semantic highlighting in some languages like java may look bad, and what's worse is that this feature is enabled by default in some languages (js, ts and c++).

Another problem is that even if the support of this feature is good in some languages, there will still be some problems, for example vscode#92308.

In fact, "add an option" itself is not the key to the problem, the key is how not to confuse users. I'll add an FAQ and mention it in the description of this option in user settings.

@ronakg
Copy link
Contributor Author

ronakg commented May 2, 2020

I agree about your reasoning, just don't agree with the solution. Users can still disable semantic highlighting at the editor level. There's no point keeping that option on at editor level and disable at theme level. Theme can utilize the same option and users still have a way to enable disable this feature.

@sainnhe
Copy link
Owner

sainnhe commented May 2, 2020

There's no point keeping that option on at editor level and disable at theme level.

The semantic highlighting is not an editor level option, it's a theme level option.

According to the official docs, a theme can enable semantic highlighting by adding this line in themes/themeName.json.

What you've done is actually overriding it in user settings.

    "editor.tokenColorCustomizations": {
        "[Gruvbox Material Dark]": {
            "semanticHighlighting": true
        }
    }

Maybe you think this option is editor level because the java extension provides an option to toggle whether to enable it, but this extension is actually interfering with theme level options. The JavaScript and TypeScript extensions officially developed by Microsoft do not provide corresponding options to enable or disable semantic level highlighting(at least I don't find it), and the official guide of TypeScript says:

Whether semantic highlighting is visible depends on the current color theme.

So I keep my point, whether to enable semantic highlighting should be controlled on the theme level.

@ronakg
Copy link
Contributor Author

ronakg commented May 2, 2020

That's interesting. Do you know what this option does?

Screen Shot 2020-05-02 at 12 03 26 AM

How does it pair with language level option and possibly theme level option?

@sainnhe
Copy link
Owner

sainnhe commented May 2, 2020

You are right. I didn't see it previously, thanks for your notice.

I am now confused about which level of option it is, but it doesn't matter. If there is already an option to control it globally, then I think it's unnecessary to add a new option any more.

I'll remove it. Thanks again :)

@sainnhe
Copy link
Owner

sainnhe commented May 2, 2020

v6.2.0 is now available on the marketplace.

@ronakg
Copy link
Contributor Author

ronakg commented May 2, 2020

Thanks. Works great with colorful syntax mode disabled.

Will it improve on it's own as Java extension provides more semantic information?

@ronakg ronakg closed this as completed May 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants