Skip to main content



      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 08:26 Go to next message
Eclipse UserFriend
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 08:31 Go to previous messageGo to next message
Eclipse UserFriend
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;
	}
Re: How to get a SemanticSyntaxHighlighter to run [message #1766359 is a reply to message #1766350] Tue, 20 June 2017 10:12 Go to previous messageGo to next message
Eclipse UserFriend
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 10:35 Go to previous messageGo to next message
Eclipse UserFriend
the MyDslIdeModule is only for usage at lsp/web

=> add this binding to MyDslUiModule
Re: How to get a SemanticSyntaxHighlighter to run [message #1766365 is a reply to message #1766360] Tue, 20 June 2017 11:15 Go to previous messageGo to next message
Eclipse UserFriend
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 11:30] by Moderator

Re: How to get a SemanticSyntaxHighlighter to run [message #1766371 is a reply to message #1766365] Tue, 20 June 2017 13:14 Go to previous messageGo to next message
Eclipse UserFriend
With or without using semantic highlighting?

Have a look at the highlighter classes I mentioned above
Re: How to get a SemanticSyntaxHighlighter to run [message #1766373 is a reply to message #1766371] Tue, 20 June 2017 13:26 Go to previous messageGo to next message
Eclipse UserFriend
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 13:27 Go to previous messageGo to next message
Eclipse UserFriend
Yes simply inject it
Re: How to get a SemanticSyntaxHighlighter to run [message #1766378 is a reply to message #1766374] Tue, 20 June 2017 14:45 Go to previous messageGo to next message
Eclipse UserFriend
No Message Body

[Updated on: Tue, 20 June 2017 15:27] by Moderator

Re: How to get a SemanticSyntaxHighlighter to run [message #1766380 is a reply to message #1766378] Tue, 20 June 2017 15:47 Go to previous messageGo to next message
Eclipse UserFriend
For the lexical highlighting it will run only if there is no semantic highlighting
Re: How to get a SemanticSyntaxHighlighter to run [message #1766389 is a reply to message #1766380] Tue, 20 June 2017 19:45 Go to previous messageGo to next message
Eclipse UserFriend
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 02:46 Go to previous message
Eclipse UserFriend
Yes semantic overrides / replaces
Previous Topic:Get All Objects of Type in Global Scope? Easy Way?
Next Topic:Scope filtering across Xtext expressions
Goto Forum:
  


Current Time: Thu May 15 12:59:41 EDT 2025

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

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

Back to the top