Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to get a SemanticSyntaxHighlighter to run
How to get a SemanticSyntaxHighlighter to run [message #1766347] Tue, 20 June 2017 12:26 Go to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
I seem to be having some problems with the configuration mechanism for the IDE package. I have written a short Semantic Highlighting provider (which is just a stub):

package obuaop.ide.highlighting

import org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.ide.editor.syntaxcoloring.IHighlightedPositionAcceptor
import org.eclipse.xtext.util.CancelIndicator

class CaopleSemanticHighlightingCalculator implements ISemanticHighlightingCalculator {
	
	override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
		System.out.println("I am here")
		throw new UnsupportedOperationException("TODO: auto-generated method stub")
	}
	
}


I then tried to write a bindISemanticHighlightingCalculator method in the CaopleIdeModule provided class, but this turned out to be impossible because it is required to return a class which extends ISemanticHighlightingCalculator, not implements it. Since there is no AbstractSemanticHighlightingCalculator class generated it seems this can't be done, so instead I went with:

class CaopleIdeModule extends AbstractCaopleIdeModule {
	
	def public configureSemanticHighlighting(Binder b) {
		System.out.println("I am here")
b.bind(ISemanticHighlightingCalculator).to(CaopleSemanticHighlightingCalculator)
	}
	
}


However, the "I am here" message is never printed so this never runs. I can't see why it wouldn't be being picked up by GetBindings in AbstractGenericModule, and there is no configuration error. What other reason would there be for this any reason why this is not running and binding? I wondered if it was because XTend is forcing a final modifier onto the Binder type in the parameter?
Re: How to get a SemanticSyntaxHighlighter to run [message #1766350 is a reply to message #1766347] Tue, 20 June 2017 12:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Hi

do you implement

org.eclipse.xtext.ui.editor.syntaxcoloring.ISemanticHighlightingCalculator

or

org.eclipse.xtext.ide.editor.syntaxcoloring.ISemanticHighlightingCalculator

here is what xtend does

	override Class<? extends ISemanticHighlightingCalculator> bindIdeSemanticHighlightingCalculator() {
		return XtendHighlightingCalculator
	}


and here what is done for the xtext editor itself

	public Class<? extends ISemanticHighlightingCalculator> bindISemanticHighlightingCalculator() {
		return SemanticHighlightingCalculator.class;
	}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to get a SemanticSyntaxHighlighter to run [message #1766359 is a reply to message #1766350] Tue, 20 June 2017 14:12 Go to previous messageGo to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
Hi Christian,

Thanks for all the help you've given on this and the other thread! I am using the version from the ide package, I originally used the ui one but I got a message that it was deprecated. I tried this:

class CaopleIdeModule extends AbstractCaopleIdeModule {
	
	def Class<? extends ISemanticHighlightingCalculator> bindIdeSemanticHighlightingCalculator() {
		System.out.println("In bind method")
		return CaopleSemanticHighlightingCalculator
	}
}


But the "in bind method" message still does not appear and there is no exception thrown when the stub method in the SemanticHighlightingCalculator tries to run.
Re: How to get a SemanticSyntaxHighlighter to run [message #1766360 is a reply to message #1766359] Tue, 20 June 2017 14:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
the MyDslIdeModule is only for usage at lsp/web

=> add this binding to MyDslUiModule


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to get a SemanticSyntaxHighlighter to run [message #1766365 is a reply to message #1766360] Tue, 20 June 2017 15:15 Go to previous messageGo to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
Ah, ok, thanks!

One other question is that the default lexical highlighting doesn't seem to be working at all. In particular it doesn't highlight keywords or literals. Is there a clearer way to specify which tokens in the grammar correspond to which style? I can see there are some examples in the documentation but they seem to use "acceptDefault" which doesn't seem right since the default isn't working. The default attribute assigned seems to work if the token's "name" is quoted, and I'm not sure how that would happen (the token can be specifies as a string in quotes but that doesn't seem to be its name)

[Updated on: Tue, 20 June 2017 15:30]

Report message to a moderator

Re: How to get a SemanticSyntaxHighlighter to run [message #1766371 is a reply to message #1766365] Tue, 20 June 2017 17:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
With or without using semantic highlighting?

Have a look at the highlighter classes I mentioned above


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to get a SemanticSyntaxHighlighter to run [message #1766373 is a reply to message #1766371] Tue, 20 June 2017 17:26 Go to previous messageGo to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
I had a look at it and I think I have the semantic highlighter working but the lexical one does not seem to be recognizing my keywords as keywords, perhaps because they are on their own in terminal rules?

Also, can my validator ask my scope provider for a scope when it is doing type checking validation?
Re: How to get a SemanticSyntaxHighlighter to run [message #1766374 is a reply to message #1766373] Tue, 20 June 2017 17:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Yes simply inject it

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to get a SemanticSyntaxHighlighter to run [message #1766378 is a reply to message #1766374] Tue, 20 June 2017 18:45 Go to previous messageGo to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
No Message Body

[Updated on: Tue, 20 June 2017 19:27]

Report message to a moderator

Re: How to get a SemanticSyntaxHighlighter to run [message #1766380 is a reply to message #1766378] Tue, 20 June 2017 19:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
For the lexical highlighting it will run only if there is no semantic highlighting

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to get a SemanticSyntaxHighlighter to run [message #1766389 is a reply to message #1766380] Tue, 20 June 2017 23:45 Go to previous messageGo to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
I think the lexical highlighting is still running.. strings, comments, etc are still coloured even though there is a semantic highlighter now. Or do you mean that it won't run on the same specific parts of the text as the semantic highlighting, because the semantic overrides it?
Re: How to get a SemanticSyntaxHighlighter to run [message #1766400 is a reply to message #1766389] Wed, 21 June 2017 06:46 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Yes semantic overrides / replaces

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Get All Objects of Type in Global Scope? Easy Way?
Next Topic:Scope filtering across Xtext expressions
Goto Forum:
  


Current Time: Tue Sep 21 12:15:06 GMT 2021

Powered by FUDForum. Page generated in 0.01893 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top