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

Provide an extension point to declare binding between Eclipse editor

Open angelozerr opened this issue 9 years ago • 10 comments

This PR provides an extension point to apply properties from .editorconfig to the editor which gains focus by converting editorconfig properties to eclipse preferences.

With this extension point, apply of preferences is not hard coded and give several improvements:

  • extensible, so now any editor can contribute to the editorconfig-eclipse.
  • update preferences only for JDT if the editor which gaisn focus is JavaEditor, only for XML, if the editor which gaisn focus is WTP XML Editor, etc
  • if the editor support it, the project preferences is updated instead of updating global preferences (JavaEditor support project preferences, but XML Editor doesn't support it). To do that the extension point provide an @scope attribute (global, project and file (when it will be supported))

angelozerr avatar Jun 08 '16 10:06 angelozerr

Please add unit tests.

ncjones avatar Jun 08 '16 11:06 ncjones

Argh-( tests are not passed because now I'm using IFile instead of using String path as parameter of editorConfigService.getEditorConfig

I will fix that at first.

angelozerr avatar Jun 08 '16 11:06 angelozerr

@ncjones I have fixed the existing JUnit tests.

My big problem is that I don't know how to do JUnit which loads my extension point. Could you help me please? Thanks!

angelozerr avatar Jun 08 '16 17:06 angelozerr

Please add unit tests.

@mickaelistria could you help me please to write JUnits with uses extension point. If you could just initialize me a JUnit which load my new extension point, I could after write tests. Thanks!

I have a lot of PR to do in order to improve the .editorconfig editor (validation, completion, etc). I'm waiting for the accept of this PR.

angelozerr avatar Jun 24 '16 10:06 angelozerr

@angelozerr I believe you only need to add a dummy extension to org.eclipse.editorconfig.core.preferencesUpdaters in the plugin.xml of your test plugin, verify that getUpdater returns it, open this editor and check that the expected preference was taken into account.

mickaelistria avatar Jun 24 '16 10:06 mickaelistria

@mickaelistria I have pushed my JUnit https://github.com/angelozerr/editorconfig-eclipse/blob/87f7fc18589d34dfc16a5cb442c1088e27090a3c/org.eclipse.editorconfig.core/src/test/java/org/eclipse/editorconfig/core/PreferencesUpdaterTest.java that I'm running with "JUnit Plugin Test" and it works well.

The build is broken (see https://travis-ci.org/ncjones/editorconfig-eclipse/builds/140056712#L459) because it executes the test with simple "JUnit" and not with "JUnit Plugin Test"

I don't know how to do that.

@ncjones @mickaelistria please help me. Thanks!

angelozerr avatar Jun 24 '16 15:06 angelozerr

Usually, Eclipse tests have to be part of a separate bundle (let's call it org.eclipse.editorconfig.core.tests), and the code have to be in the regular src/ or src/main/java folder, as described in the src.. entry of build.properties. The pom.xml file for this test bundle must say <packaging>eclipse-test-plugin</eclipse> so it will automatcally trigger the ''tycho-surefire-plugin'', that you can configure if necessary as explained in https://eclipse.org/tycho/sitedocs/tycho-surefire/tycho-surefire-plugin/test-mojo.html and https://wiki.eclipse.org/Tycho/Packaging_Types#eclipse-test-plugin

mickaelistria avatar Jun 27 '16 08:06 mickaelistria

@angelozerr Are you still interested in getting this work completed? I can help to get it integrated. I think the high level design is good. My preference is to move all the XML config into Java code as it will make the code simpler and easier to refactor. Declaritive XML support can be added later if necessary (I doubt it will be though).

ncjones avatar Apr 26 '17 10:04 ncjones

@angelozerr See also #42; we have found that a stateless mapping of editorconfig settings to Eclipse preferences can cause undesirable behavior so the declarative approach will not always be the right solution.

ncjones avatar Apr 26 '17 10:04 ncjones

@ncjones to be honnest with you, it's hard for me to find time today.

After studying some solutions, my conclusion is that it's not possible today to provide a very good plugin for .editorconfig:

  • your plugin updates the global preferences each time you open an editor. I don't remember cases, but I had troubles when I played with encoding files. My whole files of my workspace was corrupted. More it can be strange for user to see global preferences which change everytime. But you have not the choice to do that.
  • you cannot execute global action (like format) without opening the editor

See my comment at https://bugs.eclipse.org/bugs/show_bug.cgi?id=457046#c13

I would like to find a solution to support correctly .editorconfig inside Eclipse. Just find time to do that.

Hope you will understand.

angelozerr avatar Apr 26 '17 13:04 angelozerr