editorconfig-eclipse icon indicating copy to clipboard operation
editorconfig-eclipse copied to clipboard

Extension Point to apply preferences for any editor

Open angelozerr opened this issue 9 years ago • 5 comments

Today the editorconfig settings update preferences for hard coded for some Editors (JDT, Ant, XML, etc) each time an editor has focus although it could not be a supported editori (JDT preferences is updated if the editor which gains focus is a js file).

In other words, there are several problem:

  • JDT, Ant, XML, etc global preferences are updated each time any editor gains focus (this problem will be fixed by https://github.com/ncjones/editorconfig-eclipse/issues/30)
  • it's not possible to support a custom editor.

To fix those 2 problems, we could remove hard coded apply of preferences and delegate it to an extension point like this:

    <extension point="org.eclipse.editorconfig.ui.preferencesUpdaters">

        <!-- JSDT Java Editor -->
        <preferencesUpdater
            editorIds="org.eclipse.wst.jsdt.ui.CompilationUnitEditor" >
            <property from="indent_style" to="org.eclipse.jdt.core.formatter.tabulation.char" preferenceName="org.eclipse.jdt.core" >
                <value from="space" to="space" /> 
                <value from="tab" to="tab" />
            </property>
            <!-- JSDT Java Editor with indent_size -->          
            <property from="indent_size" to="org.eclipse.jdt.core.formatter.tabulation.size" preferenceName="org.eclipse.jdt.core" >
                <value type="string" />
            </property>
        </preferencesUpdater>

        <!-- Ant Editor -->
        <preferencesUpdater
            editorIds="org.eclipse.ant.ui.internal.editor.AntEditor" >
            <!-- Ant Editor with indent_style -->
            <property from="indent_style" to="formatter_tab_char" preferenceName="org.eclipse.ant.ui" >
                <value from="space" to="false" type="boolean" /> 
                <value from="tab" to="true" type="boolean" />
            </property>
        </preferencesUpdater>
    </extension>
  • editorIds is used to know which "preferencesUpdater" must be applied (convert editorconfig preference to the editor preferences)
  • property/value from/to are used to know how to convert editorconfig property to the editor peferences property.

@ncjones @mickaelistria what do you think about this idea?

angelozerr avatar May 30 '16 05:05 angelozerr

This seems like a good candidate for an extension point that allows plugin authors to provide declarative adaptors for editorconfig settings. AFAICT all the existing hard-coded editor adaptor rules could be replaced with declarations like the ones you have in the description.

@angelozerr, here's some questions:

  1. do you consider this to be different to #9? I see it as being the same issue - just a different solution proposal.
  2. do you see this as being compatible with your proposal in Bugzilla for changes to core Eclipse editor APIs or would this be an alternative approach?
  3. We still need to consider other config options that are not yet supported: tab_width, end_of_line, trailing_whitespace, final_newline and charset. How do you see those being handled with respect to this proposal? As I mentioned in #9, with the exception of tab_width, we may be able to handle all those other settings generically for any editor using editor save event hooks.

To me the ideal solution is that eclipse core has an API to get editor preferences per file that editor plugins can use and an extension point for providing overrides to those preferences that this plugin can implement. This plugin would then be a simple adaptor between editorconfig and eclipse preferences and not need to expose extension points at all. Is this a realistic goal or am I just dreaming?

ncjones avatar May 30 '16 06:05 ncjones

do you consider this to be different to #9? I see it as being the same issue - just a different solution proposal.

No it's the same issue, but I have prefered to create a new issue because there is a lot of subject inside #9

do you see this as being compatible with your proposal in Bugzilla for changes to core Eclipse editor APIs or would this be an alternative approach?

My idea is to do the same thing that your existing code but with extnesion point to give the capability to other editor like WTP JSON Editor and my TypeScript editor to consumes your plugin. My idea is to set in this extension the editor instance too in order to support preferences for editor instance when https://bugs.eclipse.org/bugs/show_bug.cgi?id=494497 will be fixed.

We still need to consider other config options that are not yet supported: tab_width, end_of_line, trailing_whitespace, final_newline and charset. How do you see those being handled with respect to this proposal?

For the moment we could hard coded that. Goal of this extension point is to define a binding between an .editorconfig property (like indent_size/[space-tab]) and an editor property name/values (like org.eclipse.jdt.core.formatter.tabulation.char/[space-tab])

If you are OK with this extension point, I will create a PR for that. Tell me just if you like name of XML elements/attributes of the extension point.

angelozerr avatar May 30 '16 12:05 angelozerr

Ok, great! I can't think of better names for the XML elements/attributes right now so go ahead.

ncjones avatar May 30 '16 12:05 ncjones

@ncjones I have implemented my idea, I will do a PR once you will accept https://github.com/ncjones/editorconfig-eclipse/pull/38

This PR will give the capability to

  • gives the capability to consume your plugin with a custom editor by using this extension point
  • apply preferences only for the well preferences (JDT preferences if it's a JavaEditor)
  • apply preferences for global (like today) or project preferences (if the editor support it)

For the moment I use the editor id, but perhaps it should be improved (use file extension, content type, implement an "extend" like (ex : POM Editor extends WTP XML editor, so it uses preferences of WTP XML Editor and you don't need to declare for POM Editor))

I have continued to study how to support preferences for editor instance. I have some idea but it will not work if the editor doesn't support it. In my case I would like to support it for my TypeScript Editor.

angelozerr avatar May 31 '16 20:05 angelozerr

@ncjones see my PR https://github.com/ncjones/editorconfig-eclipse/pull/39

angelozerr avatar Jun 08 '16 10:06 angelozerr