I implemented the belowed code into MySemanticHighlightingCalculator and the color for the one element changes as expected. But the default default highlighting, like the purple color for keywords didn’t work anymore.
INode root = resource.getParseResult().getRootNode();
BidiTreeIterator<INode> iterator = root.getAsTreeIterable().iterator();
while (iterator.hasNext()) {
INode node = iterator.next();
if (node.getSemanticElement() instanceof ParameterDesc) {
ParameterDesc paramdesc = (ParameterDesc) node
.getSemanticElement();
if (paramdesc.isUnselected() == true) {
acceptor.addPosition(
node.getOffset(),
node.getLength(),
MySemanticHighlightingConfiguration.PARAMETER_DESCRIPTION);
}
}
}
public static final String PARAMETER_DESCRIPTION = "Parameter_Description";
public void configure(IHighlightingConfigurationAcceptor acceptor) {
addType(acceptor, PARAMETER_DESCRIPTION, 255, 0, 0, TextAttribute.STRIKETHROUGH);
}
public void addType(IHighlightingConfigurationAcceptor acceptor, String s,
int r, int g, int b, int style) {
TextStyle textStyle = new TextStyle();
textStyle.setColor(new RGB(r, g, b));
textStyle.setStyle(style);
acceptor.acceptDefaultHighlighting(s, s, textStyle);
}
But when I remove the MySemanticHighlightingConfiguration from MyDSLUiModule, the default highlighting work again:
public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration() {
return MySemanticHighlightingConfiguration.class;
}
I know that the default highlighting will not be applyed between offset and offset+length, but I want it for the rest of the document.
Your highlighting configuration has to extend the
DefaultHighlightingConfigurationand you have to invokesuper.configure(). That will do the trick.Please note that
resource.getParseResult()may be null in some rare situations.