-
Notifications
You must be signed in to change notification settings - Fork 453
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
Declare semantic token type for modifier keywords #1636
Declare semantic token type for modifier keywords #1636
Conversation
@Eskibear please review when you can |
4b9527f
to
5e4ed0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that "modifier" inherits from "keyword", otherwise vscode doesn't know the token (althought it's defined in LSP3.16)
"storage.type.annotation.java" | ||
], | ||
"annotationMember": [ | ||
"constant.other.key.java" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking @SuppressWarnings(value="all")
for example. "value" is annotationMember
and its definition is:
public @interface SuppressWarnings {
/*....*/
String[] value(); //<---HERE
}
I wonder "constant" is not proper for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't entirely sure what TextMate scope made the most sense, and just used the same scope as in the default Java TextMate grammar. If we decide to use some other scope it might break existing color themes, although I guess you could work around that by adding multiple TextMate scopes.
I do see another issue (maybe this is what you meant), which is that annotation member declarations are now given the same scope as annotation members inside of an annotation like @SuppressWarnings(value = "all")
. It's definitely possible to add scope a different scope mapping for annotationMember.declaration
, but the question is again which TextMate scope it should have?
In the default Java grammar, annotation member declarations are treated like regular methods, and therefore get the entity.name.function.java
and meta.function-call.java
scopes. We could add those scopes to annotation member declarations for backwards compatibility, but we could also add a more specific annotation member scope. Again, these alternatives doesn't have to be mutually exclusive as you can declare an array of TextMate scopes in the contribution point.
So what do you think? Should we mirror the behaviour of the default TextMate grammar (and tell users to style using semantic highlighting for more specific rules) or should we also add more specific/correct TextMate scopes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In current behavior, "value" is highlighted as function name, because you define annotationMember
as a subtype of function
. And it makes some sense because of the consistency, i.e., when you go to definition of "value", it's also highligted as a function.
My point is, although default textMate grammar use "constant.other.key.java", it is not proper for the scope. constant.*
is for constant values like string literals, numbers, etc. See https://macromates.com/manual/en/language_grammars#naming_conventions
And it's not picked up by the default theme.
So I prefer here to use a more specific/correct TextMate scope, maybe something looks like entity.name.annotationMember
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no expert on TextMate grammars and naming conventions, but I agree that entity.name.annotationMember
sounds more correct than constant.other.key
. I'll modify this PR to include the entity.name.annotationMember
scope for annotation members then.
@Eskibear @0dinD does it make sense to merge eclipse-jdtls/eclipse.jdt.ls#1539 independently from this? Or should we expect more changes upstream? |
I think eclipse-jdtls/eclipse.jdt.ls#1539 is safe to merge independently.
I tested eclipse-jdtls/eclipse.jdt.ls#1539 independently (without this PR), but didn't see any regression with default theme. See below, there's no textMate scope for the |
@fbricon I initially thought that not using this PR would cause modifier keywords to lose their color, similar to what happened when we introduced the This PR mainly adds consistency between semantic highlighting and TextMate grammars. Also, I don't think the |
5e4ed0c
to
c29093e
Compare
Signed-off-by: 0dinD <[email protected]>
c29093e
to
63fe4aa
Compare
I just updated this PR to include the |
@Eskibear can we merge this one? |
@fbricon LGTM, safe to merge. |
Part of eclipse-jdtls/eclipse.jdt.ls#1539.
Declares semantic token type for
modifier
, and supertypes it tokeyword
. Also adds scope mapping for the custom token types, since that was missing. This means that themes still using TextMate scopes can style semantically highlighted modifier keywords, annotations and annotation members.