Async highlighter [message #963143] |
Mon, 29 October 2012 15:54  |
|
Hi there,
I would like to have an embdedded editor with async highlighting. As I can see from the code the common way of contribute computed styles is to be a listener on "LineStyle" and handle back the styles as ranges in the event.
view.addEventListener("LineStyle", this._listener.onLineStyle);
_onLineStyle : function(e) {
e.ranges = this._computeStyles();
};
But if I handle back the data async (via promise) they are ignored. I can image that the queue of listeners are already processed so the ranges are not recognized.
_onLineStyle : function(e) {
this._calculateRanges().then(function(data){
e.ranges = data;
});
}
Is there an other common way to calculate the ranges async?
Thanks,
Holger
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
Re: Async highlighter [message #963925 is a reply to message #963143] |
Tue, 30 October 2012 05:53   |
Mark Macdonald Messages: 35 Registered: July 2009 |
Member |
|
|
Hi Holger,
You are correct: the basic TextView (and Editor) APIs are synchronous. However the Orion IDE does support asynchronous calculation of styles -- this is done through a service extension point named "orion.edit.highlighter". (It is not part of the embedded-editor example; you'll have to manually add the support yourself. The process is a bit advanced and involves Orion services.)
If you are interested in trying this, here's an outline of what you'd have to do:
- Implement a service object that will do the actual async calculation of your styles. This object needs to have a dispatchEvent method that returns an event (or a Deferred resolving to an event) of type "orion.edit.highlighter.styleReady". The event also contains your style information, so it must have a lineStyles field as described here.
- Ensure your app loads the asyncStyler.js and serviceregistry.js modules.
- Create a new ServiceRegistry. Call its #registerService() method as follows:
serviceregistry.registerService("orion.edit.highlighter", yourServiceObject, { type: "highlighter" });
- Create a new AsyncStyler passing your TextView, and your ServiceRegistry. (Optionally an AnnotationModel can be passed if your service wants to provide error/warning annotations as well).
Once the AsyncStyler has been set up, it works as follows: AsyncStyler listens for "orion.edit.highlighter.styleReady" events from your service object. When an event is received, the style information is passed to TextView#onLineStyle(), which styles appropriate line(s). This may cause the TextView to be redrawn, so for efficiency your service should provide styles for many lines in each event.
For reference, see this Orion plugin [1] which implements a "orion.edit.highlighter" service. (Your app will not need the "PluginProvider" API, so just read it as "ServiceRegistry".)
Regards,
Mark
[1] https: //github.com/mamacdon/orion-codemirror/blob/master/src/lib/codeMirrorPlugin.js#L155-175
[Updated on: Tue, 30 October 2012 05:54] Report message to a moderator
|
|
|
Re: Async highlighter [message #964099 is a reply to message #963925] |
Tue, 30 October 2012 08:58   |
|
Thanks Mark,
beside the fact that I have to use the serviceregistry I was on the right trac I think. I'll try to make that run and give feedback here. Thanks for the quick answer.
Cheers,
Holger
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
|
Powered by
FUDForum. Page generated in 0.01953 seconds