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

Use a custom color for Java Annotations #6749

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lkishalmi
Copy link
Contributor

I'm doing some small work with Micronaut lately, and wished that the annotations would be more distinctive in the editor.

It seemed it is not that easy to set a different color for them. First the @ and the ... tokens were marked as special, though no coloring support were assigned to that key. I've checked the Lang Spec, they are called as separators (at least in 8).

Also changing the color in the annotation use (or actually XXX Use) would make the import statements rainbow, so I had to skip those. Actually there is a possibility to use different colors for the imported identifiers, if someone would think that useful.

Lastly, added localization for the mod-keyword coloring. That is not in actual use as there are some bugs in the code. I do not know the correct intention of that modifier, How I'd get it that those are keywords that are keywords by their context, not a simple token in the Lexer.

Ides, feedback are welcome!

This is with FlatLaf Light:
image

This is with FlatLaf Dark
image

@lkishalmi lkishalmi added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) Editor labels Nov 25, 2023
@lkishalmi lkishalmi added this to the NB21 milestone Nov 25, 2023
@lkishalmi lkishalmi marked this pull request as draft November 25, 2023 15:14
Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the added ability to customize annotation colors. But the colors itself might need some tweaks though ;)

I recommend to wait a bit till Neil is active again, he has a good eye for things like this I think.

I personally would probably prefer a desaturated version of the type modifier color.
image
image

here is a problem, annotations are tracked as identifier in the options if you click on it + preview doesn't use the right color:
image

put("mod-keyword", KEYWORD);
//put("mod-keyword", KEYWORD);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not. I was trying to figure out what exactly it is used for. I'm still not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the semantic highlighter it would be mostly used from the parser info in module-info.java files. But right now we do not parse that section of the code (in the semantic highlighter).

@lkishalmi
Copy link
Contributor Author

I've marked the PR as a preview to have a discussion on this. There are a few test and test data to be fixed according to the outcome of this discussion.

Would it make sense to add coloring to the import statements?

To me it also would make sense to have the @ as normal separator and use the semantic highlighter to change that color when used together with an annotation type otherwise @interface might look odd. I do not know. Let's talk about this!

@lkishalmi
Copy link
Contributor Author

@mbien The preview use the lexer only. I'm testing if I can add a highlighter there as well, that would come in a separate PR, if I can make that happen.

@mbien
Copy link
Member

mbien commented Nov 26, 2023

Would it make sense to add coloring to the import statements?

you mean the fully qualified type behind import?

import java.util.ArrayList;
//     ^^^^^^^^^^^^^^^^^^^ this?

not sure. To me it is probably not necessary, since it should probably have the same color as:

list = new java.util.ArrayList<>();
//         ^^^^^^^^^^^^^^^^^^^ <- essentially the same thing

Or do you mean something else?

There are two separate questions to ask I think: what should the editor offer and which part should be used in the default theme.
It could be nice to have an option to customize import statements but maybe it shouldn't be enabled by default. Although I think it would probably look nice to reduce saturation for the imports on some themes which have the contrast budget for that since those code areas are generally less import-ant :)

e.g I am experimenting with a higher contrast theme based on flatlaf dark which would probably have the contrast budget to tone imports down a bit:
image

@lkishalmi
Copy link
Contributor Author

  1. Yes, I mean the FQN after the import. Right now if you start use different colors by element kind it would look like this:
    image

  2. I have not really thought about the colors, defaults yet, other than I wish to put some emphasis/distinction on annotations.

@neilcsmith-net neilcsmith-net modified the milestones: NB21, NB22 Jan 12, 2024
@ebarboni ebarboni modified the milestones: NB22, NB23 Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Editor Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants