Highlighting of hidden elements is not as expected [message #1697058] |
Mon, 01 June 2015 09:15 |
Jean Cauvin Messages: 2 Registered: June 2015 |
Junior Member |
|
|
Hello experts,
I use XText for several weeks and have basic understanding of the framework. My question is this: In my grammar I have rules like these (it's only an excert from a more complex grammar). In fact, this is a slight modification of the default comment rules (which are hidden along with whitespaces) to introduce some sort of my own comments containing Doxygen documentation. These rules are not hidden.
/* documentation comment */
DocCommentElement:
text = ( SL_DOC_COMMENT | ML_DOC_COMMENT )
terminal ML_DOC_COMMENT: '<#' -> '#>';
terminal SL_DOC_COMMENT: '#' !('\n'|'\r')* ('\r'? '\n')?;
Now I want to highlight them in a custom color. I successfully achieve this by providing my own implementation of ISemanticHighlightingCalculator and IHighlightingConfiguration. This is the code:
public class MyHighlightingConfiguration extends DefaultHighlightingConfiguration
{
// provide ID strings for the highlighting calculator
public static final String DOCUMENTATION_COMMENT_ID = "documentation comment";
@Override
public void configure(IHighlightingConfigurationAcceptor acceptor)
{
// let the default implementation first do the job
super.configure(acceptor);
// here our custom styles are used
acceptor.acceptDefaultHighlighting(DOCUMENTATION_COMMENT_ID, "Documentation comment", documentationCommentTextStyle());
}
public TextStyle documentationCommentTextStyle() {
TextStyle textStyle = defaultTextStyle().copy();
textStyle.setColor(new RGB(63, 95, 191)); // default Eclipse JavaDoc color
return textStyle;
}
}
public class MySemanticHighlightingCalculator implements ISemanticHighlightingCalculator
{
@Override
public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor)
{
if (resource == null || resource.getParseResult() == null)
return;
INode root = resource.getParseResult().getRootNode();
for (INode node : root.getAsTreeIterable())
{
if (node.getSemanticElement() instanceof DocCommentElement)
{
acceptor.addPosition(node.getOffset(), node.getLength(),
MyHighlightingConfiguration.DOCUMENTATION_COMMENT_ID);
}
}
}
}
I notice a problem in a particular case and I don't know - is it my own mistake or a bug in the framework. Expected behavior is:
// default comment (should be green)
# my own comment (should be blue)
In this case I get the following result:
// default comment (should be green)
# my own comment (should be blue)
It seems, that if hidden text is immediately before my own comment, it takes its color. In other cases everything works as expected, colors are correct. Can you point me to an error in my grammar/implementation or confirm this as a bug in the framework? Thank you in advance!
P.S. I use this environment:
Eclipse Version: Luna SR2 (4.4.2) M20150204-1700
Xtext: 2.8.1.v201503230617
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03406 seconds