Bug 507753

Summary: [Generic Editor] Specify IPresentationReconcilier without extension point
Product: [Eclipse Project] Platform Reporter: Angelo ZERR <azerr>
Component: TextAssignee: Mickael Istria <mistria>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, gautier.desaintmartinlacaze, mistria
Version: 4.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on: 507772    
Bug Blocks:    

Description Angelo ZERR CLA 2016-11-18 07:59:22 EST
My main goal is to find a solution to specify a IPresentationReconcilier to a GenericEditor without extension point. Indeed https://github.com/angelozerr/textmate.java which gives support for TextMate syntax colorization provides a generic IPresentationReconcilier TMPresentationReconcilier:

For instance for LS C#, JSON, CSS GenericEditor you must just define extension point like this:

-----------------
<extension
         point="org.eclipse.ui.genericeditor.presentationReconcilers">
      <presentationReconciler
            class="org.eclipse.language.textmate.eclipse.text.TMPresentationReconciler"
            contentType="org.eclipse.languageserver.languages.csharp">
      </presentationReconciler>
      <presentationReconciler
            class="org.eclipse.language.textmate.eclipse.text.TMPresentationReconciler"
            contentType="org.eclipse.languageserver.languages.json">
      </presentationReconciler>
      <presentationReconciler
            class="org.eclipse.language.textmate.eclipse.text.TMPresentationReconciler"
            contentType="org.eclipse.languageserver.languages.css">
      </presentationReconciler>      
   </extension>
-----------------

I would like to give the capability to the user to specify a TextMate grammar to use for her own grammar:

 * user register in a TextMate preferences her grammar and select a content type (or create a new content type (but it's not possible for the moment).
 * after that user opens a GenericEditor and the editor should be colorized by consumming her grammar.

To do that, I need to have the capability to set the TMPresentationReconciler to the GenericEditor with the selected/created content type.

Any suggestion are welcome!
Comment 1 Mickael Istria CLA 2016-11-18 10:56:18 EST
You can associate directly with the 'org.eclipse.core.runtime.text' content type, so it will associate with all types.
At the moment, there is an issue that only the 1st (with an unspecified order...) presentationReconcilier is used. So doing so would disable other presentation reconciliers... There is room for improvement about it in the Generic Editor, for example by ignoring the current presentation reconcilier if it doesn't change anything and by using the "next" one. I've opened bug 507772 to track this specific idea. Do you think it would be a good solution for your use-case?
Comment 2 Angelo ZERR CLA 2016-11-18 11:22:10 EST
> You can associate directly with the 'org.eclipse.core.runtime.text'

I understand your suggestion, I could do just:

-----------------------
<extension
         point="org.eclipse.ui.genericeditor.presentationReconcilers">
      <presentationReconciler           class="org.eclipse.language.textmate.eclipse.text.TMPresentationReconciler"
            contentType="org.eclipse.core.runtime.text">
-----------------------

And it will work for any languages C#, JSON, CSS, other. 
But it doesn't work (perhaps you don't use IContentType.isKindOf)?

After if I will able to do that, it means that I must check in my code that grammar doesn't exists and don't throw an error, but it's OK for me.

> I've opened bug 507772 to track this specific idea. Do you think it would be a good solution for your use-case?

Yes I think if I can declare just for any content types:

-----------------------
<extension
         point="org.eclipse.ui.genericeditor.presentationReconcilers">
      <presentationReconciler           class="org.eclipse.language.textmate.eclipse.text.TMPresentationReconciler"
            contentType="org.eclipse.core.runtime.text">
-----------------------