Community
Participate
Working Groups
Quoting Andreas: Keywords should be highlighted in keyword-color when in a keyword position and highlighted in identified color when in an identifier position: ${int:import(java.lang.Integer)} Ideally, int would not be highlighted as keyword, but as identifier.But this might be a bit trickier, as the token is certainly the keyword "int"; only the grammar rule that applies is something like IdentifierOrKeyword. But AFAIK Xtext has a two-phase syntax colorer; on that quickly colors based on token-type alone and one that re-colors based on grammer-rule/AST-node-type.
Here are some more cases which are not covered by the current implementation (patch set 6 of <https://git.eclipse.org/r/#/c/27862/>): int[] array; // "array" is highlighted but should not be Object var = null; // "var" is highlighted but should not be I think the grammar needs to treat template language keywords outside their ${...} context just as it treats Java keywords inside the ${...}.
Ok. I have a question about this. For example, in the case of int[] array; the word array will be treated as an JavaIdentifier. The same goes for var. Nothing outside the template variables is treated as a template language keyword.(the grammar does not allow it). My question is: do we want JavaIdentifiers highlighted or not? And if we don't, what exactly is the point of the JavaIdentifier grammar rule? Is is really necessary?
(In reply to Stefan Prisca from comment #2) > Ok. I have a question about this. > > For example, in the case of > > int[] array; > > the word array will be treated as an JavaIdentifier. The same goes for var. > Nothing outside the template variables is treated as a template language > keyword.(the grammar does not allow it). > > My question is: do we want JavaIdentifiers highlighted or not? I don't think we should highlight Java identifiers *by default*. We should, however, *be able* to distinguish when an identifier is used as a Java identifier and when an identifier is used as a template language identifier. Just like we should be able to distinguish between Java keywords and template language keywords. That way the user can configure whether he wants to use the same or different highlight colors for Java and template language keywords (currently, both a purple) and whether to use different highlights for Java and template language identifiers (currently, both a not highlighted). In particular, using different colors for Java and template language keywords sounds like a real usability improvement to me. Does this sound like a reasonable goal?
Yes it does. We can set the default token color using the DefaultAntlrTokenToAttributeIdMapper class.(See Lexical Highlighting from [1]) This will color the Java Identifiers with black (or with a java identifier text style which the user will then be able to change) by default at the token level. Which also means that we will not worry about JavaIdentifiers in the HighlightCalculator anymore. What do you think? [1]: http://www.eclipse.org/Xtext/documentation.html#highlighting
Fixed with change <https://git.eclipse.org/r/#/c/27862/> For further discussions about template keywords highlighting please refer to bug <https://bugs.eclipse.org/bugs/show_bug.cgi?id=436902>