Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Orion » Async highlighter(How to make style computation async)
Async highlighter [message #963143] Mon, 29 October 2012 11:54 Go to next message
Holger Schill is currently offline Holger Schill
Messages: 68
Registered: July 2009
Member
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 01:53 Go to previous messageGo to next message
Mark Macdonald is currently offline Mark Macdonald
Messages: 21
Registered: July 2009
Junior 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:

  1. 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.
  2. Ensure your app loads the asyncStyler.js and serviceregistry.js modules.
  3. Create a new ServiceRegistry. Call its #registerService() method as follows:
       serviceregistry.registerService("orion.edit.highlighter", yourServiceObject, { type: "highlighter" });

  4. 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 01:54]

Report message to a moderator

Re: Async highlighter [message #964099 is a reply to message #963925] Tue, 30 October 2012 04:58 Go to previous messageGo to next message
Holger Schill is currently offline Holger Schill
Messages: 68
Registered: July 2009
Member
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
Re: Async highlighter [message #964237 is a reply to message #964099] Tue, 30 October 2012 07:06 Go to previous message
Holger Schill is currently offline Holger Schill
Messages: 68
Registered: July 2009
Member
Hi Mark,

works like a charm. Thanks.

Cheers,
Holger


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:Need help writing Authentication Plugin
Next Topic:How to write a command that provisions a file into the user's directory?
Goto Forum:
  


Current Time: Fri Aug 29 10:16:54 EDT 2014

Powered by FUDForum. Page generated in 0.08906 seconds