|
Re: Semantic Highlighting [message #1694497 is a reply to message #1694493] |
Tue, 05 May 2015 16:05 |
|
Hi,
i dont know any resource on that but it has not really changed since the old days of 0.8 and 1.0
the point that has changed is the node model that is (often) used to do the highlighting.
so what you basically do is to traverse the node model and assign configIds to the nodes.
the domain model example contains a starting point for that
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Semantic Highlighting [message #1694505 is a reply to message #1694503] |
Tue, 05 May 2015 17:46 |
|
Hi,
the grammar elements are elements of the xtext metamodel and not of your metamodel.
you have basically two options
(1) use node model as starting point
public class MyDslSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator{
@Inject
MyDslGrammarAccess ga;
@Override
protected void doProvideHighlightingFor(XtextResource resource,
IHighlightedPositionAcceptor acceptor) {
ICompositeNode rootNode = resource.getParseResult().getRootNode();
for (INode node : rootNode.getAsTreeIterable()) {
if (node.getGrammarElement() == ga.getGreetingAccess().getNameIDTerminalRuleCall_1_0()) {
acceptor.addPosition(node.getOffset(), node.getLength(), DefaultHighlightingConfiguration.KEYWORD_ID);
}
}
super.doProvideHighlightingFor(resource, acceptor);
}
}
(2) use eobject tree as starting point
public class MyDslSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator{
@Override
protected void doProvideHighlightingFor(XtextResource resource,
IHighlightedPositionAcceptor acceptor) {
EObject rootObject = resource.getParseResult().getRootASTElement();
for (Greeting g : EcoreUtil2.getAllContentsOfType(rootObject, Greeting.class)) {
for (INode node : NodeModelUtils.findNodesForFeature(g, MyDslPackage.Literals.GREETING__NAME)) {
acceptor.addPosition(node.getOffset(), node.getLength(), DefaultHighlightingConfiguration.COMMENT_ID);
}
}
super.doProvideHighlightingFor(resource, acceptor);
}
}
p.s: it helps to inspect the node model using a debugger to find out what is there
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Semantic Highlighting [message #1694529 is a reply to message #1694505] |
Wed, 06 May 2015 02:11 |
Bob Tao Messages: 23 Registered: March 2015 |
Junior Member |
|
|
Hi, Christian!
where should I add "MyDslSemanticHighlightingCalculator" and let it run?
I can't found the method to be override in "MyDslUiModule".
////// I solve it.
@Override
public void configure(Binder binder) {
// TODO Auto-generated method stub
super.configure(binder);
binder.bind(DefaultSemanticHighlightingCalculator.class).to(UclSemanticHighlightingCalculator.class);
}
[Updated on: Wed, 06 May 2015 02:47] Report message to a moderator
|
|
|
|
|
|
Re: Semantic Highlighting [message #1694564 is a reply to message #1694558] |
Wed, 06 May 2015 11:04 |
|
sorry have no idea for that (is not connected to semantic highlighting at all).
do you use toggle with outline feature? there is already stuff highlighted.
=> you have only to find out where these colors come from.
maybe they can be configured in the preferences
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06778 seconds