Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#514 Add Gradle editor #564

Closed
wants to merge 24 commits into from
Closed

#514 Add Gradle editor #564

wants to merge 24 commits into from

Conversation

cmoine
Copy link
Contributor

@cmoine cmoine commented Sep 8, 2017

I have used the genericeditor. It was almost too simple :)

Appart from the joke, I wanted to use a more sophisticated highlighter rules... For example "task" is defined as a keyword but it is not. It is related to Gradle DSL.... So if you invoke a task like for instance:

myTask task: 'anotherTask'

task will be highlighted :( It seems we need some kind of semantic parser to do that. I tried (https://github.com/danielsun1106/groovy-parser), but I am not sure parsing the document for highlight syntax is good (I think I can imagine the answer :D ).

If you of someone else have experience on that, I am very interested with these problematic :)

I know Gradle DSL is complex, and it is probably the reason why there is not bundled Gradle editor in Eclipse :D Even if Eclipse seem to bet more on Kotlin DSL to provide an editor, I don't think it will be quickly the most used editor...

It is why I kept it simple so far :)

I also took the opportunity to add a EditorContributor for #560 :)

eclipse#560 Add editor contribution

Signed-off-by: Christophe Moine <christophe.moine@free.fr>
@donat donat self-requested a review September 12, 2017 15:14
Copy link
Contributor

@donat donat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to give your PR a go, but it seems to be that the changes don't compile ATM.
Could you please try building your project locally (./gradlew build should do the trick) and update the PR?
Besides, there are a lot of style issues: missing headers, tabs instead of spaces, and so on. The build process will indicate those problems, so fixing should be straightforward.
There is some cleanup needed in the code, but first, let me see it in action :)

@cmoine
Copy link
Contributor Author

cmoine commented Sep 13, 2017

Sorry, I setup a new environment properly with Oomph :)

I tried also to rebase on master branch, I hope there will be no trouble with that... :O

donat and others added 20 commits September 13, 2017 14:01
The FixedRequestAttributesBuilder class was removed in the 2.1.0
release, even though it's used by existing STS releases. To resolve
the situation we re-added and deprecateted this class.
The Spring Tool Suite has a dependency to Guava 15 and to Buildship.
Due to how the dependencies are currently set up, the only way to
make STS and Buildship work together is to use Guava 15 everywhere.

This reverts commit c7f47e5.
This commit fixes a regression introduced in Buildship 2.1. The
new preferences API ignored the project location and always
executed all tasks on the root project. As a result, task selectors
were always executed on all projects, even if they were started from
a subproject.

The fix changes the RunConfiguration interface such that it references
a project config as opposed to a build configuration.

This commit fixes eclipse#520
Until 2.1 Buildship accepted absolute root project location in the
import preferences.
Signed-off-by: Andy Wu <andy.wu@liferay.com>
Copy link
Contributor

@donat donat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are getting closer! I've tried out the editor and it feels so much nicer than using the simple text editor.

I've added a couple of suggestions how to clean up the code and how to make the new functionality simpler.

There's one thing besides my review comments. Can you please rebase your branch to the latest master so that only your files appear in the review? It's a bit annoying that I have to go through 65 files, even though your change touches ~6 files. Plus, there's already a merge conflict in one of the manifest files.

<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions="gradle"
id="org.eclipse.buildship.core.gradleScript"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

org.eclipse.buildship.core.files.gradlebuildscript

<content-type
file-extensions="gradle"
id="org.eclipse.buildship.core.gradleScript"
name="Gradle Build File"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gradle Build Script

@@ -0,0 +1,29 @@
package org.eclipse.buildship.ui.editor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing header.

import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.EditorActionBarContributor;

public class GradleEditorContributor extends EditorActionBarContributor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing javadoc. Please run the build and fix all these issues. If you have any problems running the build (should be as easy as executing ./gradlew build) just let me know and I'll help.

import org.eclipse.ui.part.EditorActionBarContributor;

public class GradleEditorContributor extends EditorActionBarContributor {
private static final String REFRESHPROJECT_COMMAND_ID = "org.eclipse.buildship.ui.commands.refreshproject";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this ID to the UiPluginConstants class.

class="org.eclipse.ui.editors.text.TextEditor"
icon="icons/full/obj16/gradle_file.png"
name="Gradle Build Script Editor"
class="org.eclipse.ui.internal.genericeditor.ExtensionBasedTextEditor"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really have to use an internal class here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point, but I don't see other way to define an icon for the editor, and most important: an editorcontributor to add "Refresh Gradle Project" action in the toolbar.


public class GradlePresentationReconciler extends PresentationReconciler {
private static final List<String> GRADLE_IDENTIFIERS=Arrays.asList(
// Java keywords
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clean up the indentation and remove the comments.

* @author Benjamin gurok
* @author Paul Verest
*/
public class GradleEditorPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a simple editor and thus we should keep it simple. How about we

  • remove the preference page
  • reuse the colors from the Java editor (org.eclipse.jdt.ui.PreferenceConstants)
  • Add a preference listener to update the colors when the Java editor colors changed.
    This way we can provide a consistent color scheme without adding more complexity to the UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitated reusing Java Colors. I will see if that fits.

@cmoine
Copy link
Contributor Author

cmoine commented Sep 14, 2017

Ok, no pb. Do you mind if I create a new PR ? I would like to create a clean new branch on my fork.

@donat
Copy link
Contributor

donat commented Sep 14, 2017

Aure, go ahead. Actually, it makes sense as changing this PR might mess up the review comments.

@cmoine
Copy link
Contributor Author

cmoine commented Sep 15, 2017

It seems that colors for Java Syntax depends on the used Theme. With dark theme, keywords are orange instead of violet. Do you know how to take the Theme into account ? I had a look yesterday, but I haven't found in a "reasonable" timing :) If you already know, I would be very interested, thanks.

eclipse#560 Add editor contribution

Signed-off-by: Christophe Moine <christophe.moine@free.fr>
@donat
Copy link
Contributor

donat commented Sep 15, 2017

You can attach a listener to the JDT UI plugin preferences. Here's an example:

EclipsePreferencesUtils.getInstanceScope().getNode(JavaUI.ID_PLUGIN)
    .addPreferenceChangeListener(new IPreferenceChangeListener() {

    @Override
    public void preferenceChange(PreferenceChangeEvent event) {
        if (event.getKey().equals(PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR)) {
           System.out.println(JavaUI.getColorManager()
               .getColor(PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR));
        }
    }
});

A small note: The EclipsePreferencesUtils is a utility class from Buildship.

@donat
Copy link
Contributor

donat commented Sep 20, 2017

Can we help anything regarding this PR?

@cmoine
Copy link
Contributor Author

cmoine commented Sep 20, 2017

Thanks but I haven't much time this week, but don't worry, I'm on it :)

Also the current implementation of the PresentationReconcilier don't support the addPreferenceChangeListener.
I made I short test:

UiPlugin.getInstance().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(GradleEditorConstants.KEY_COLOR_KEYWORD)) {
                    GradlePresentationReconciler.this.keywordToken.setData(new TextAttribute(Display.getDefault().getSystemColor(SWT.COLOR_DARK_YELLOW), null, UiPlugin.getInstance().getPreferenceStore().getBoolean(GradleEditorConstants.KEY_BOLD_KEYWORD) ? SWT.BOLD : SWT.NORMAL));
                }
            }
        });

But as expected, the setData with a new TextAttribute doesn't refresh the editor...

JDT use setData with string (token ids) instead of TextAttribute, and I need to use something similar I guess.

@cmoine
Copy link
Contributor Author

cmoine commented Sep 20, 2017

Ok, I made some progress, but it seems a long way home :(

It seems that we need a "Reconcilier". The PresentationReconcilier is not sufficient. unfortunately, only genericeditor v1.1 let us define a Reconcilier... Either I need to get ride of genericeditor, or we need to migrate to genericeditor 1.1. What do you think ?

@cmoine
Copy link
Contributor Author

cmoine commented Sep 20, 2017

Hmm, sorry, but it seems that genericeditor it too far from what you expect: the editor doesn't override affectsTextPresentation which allows colors changing "on the fly"

@donat
Copy link
Contributor

donat commented Sep 20, 2017

I think it would be already fine if the editor colors would be updated after the editor is closed and reopened. Theme updates are not that frequent anyway.

But there's yet another problem with the generic editor. Since the dependency is relatively new, we can only ship with it Buildship only for the latest version. So, if we set the org.eclipse.buildship.ui.genericeditor dependency to 1.1, then the editor support will be available in Eclipse 4.8+, maybe 4.7.1, I'm not 100% sure (I'd adjust the build scripts, you don't have to worry about that).

That being said, I think I'm leaning towards going back to the initial idea of having a discrete editor definition. That way we can support previous Eclipse versions and we have full control over the color preferences. How does that sound to you?

In any case, thanks for sticking with us! We are super grateful that you invest your time into this feature.

@cmoine
Copy link
Contributor Author

cmoine commented Sep 21, 2017

I totally agree. My experiments with genericeditor are not conclusive unfortunately :(

@cmoine
Copy link
Contributor Author

cmoine commented Sep 25, 2017

I love Eclipse, but... the Syntax Hightlighthing mechanism with Reconcilier/Damager/Partitioner is just a nightmare !!!
Do you mind if I use the internal org.eclipse.jdt.internal.ui.text.AbstractJavaScanner ?

@cmoine
Copy link
Contributor Author

cmoine commented Sep 25, 2017

Damned, I found the magic method to make it work with genericeditor:
viewer.invalidateTextPresentation()
Sorry for the n-th change, but I recommend to use generic editor: Defining our own editor/presenter/reconcilier require a LOT OF CODE, and sometimes references to internal Java Plugin if we don't want to copy paste too much :(

What do you think ?

PS: both solution are almost working, we simply need to choose, but I am less confident with the solution without genericeditor, because there is so much bunch of code I took from other that am not in full control :(

@donat
Copy link
Contributor

donat commented Sep 25, 2017

I'd prefer genericeditor if we can use viewer.invalidateTextPresentation() and if we don't need the 1.1 version just to update the colors upon the theme changes.

@cmoine
Copy link
Contributor Author

cmoine commented Sep 26, 2017

omg, spent one day figuring out with Generic Editor doesn't work... It definitely doesn't fit. The partitionning/damager/reconciler is definitely complex stuff, and Generic Editor doesn't fit. I will switch back the plain old implementation again :'-( (without generic editor) If somebody interested, the limitation comes from this (in SourceViewerConfiguration), which is not properly extendable within GenericEditor:

public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
	return new String[] { IDocument.DEFAULT_CONTENT_TYPE };
}
public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
	return IDocumentExtension3.DEFAULT_PARTITIONING;
}

Now I think I understand why there is not Gradle editor :D

@cmoine
Copy link
Contributor Author

cmoine commented Sep 28, 2017

I am almost ready to push the "non generic editor" solution, is it ok ?

@donat
Copy link
Contributor

donat commented Sep 28, 2017

Sure, please go ahead.

types + Reuse Java syntax color highlighting

Signed-off-by: Christophe Moine <christophe.moine@free.fr>
types + Reuse Java syntax color highlighting

Signed-off-by: Christophe Moine <christophe.moine@free.fr>
@cmoine
Copy link
Contributor Author

cmoine commented Sep 28, 2017

Pushed.

@cmoine
Copy link
Contributor Author

cmoine commented Sep 28, 2017

Sorry for my clumpsy usage of Git :(

@donat
Copy link
Contributor

donat commented Sep 28, 2017

Thanks for the change, I'll have a look shortly.

In the meanwhile, here's what I usually do on the command line when I want to produce a PR with a single commit:

# count the commits I have on the local branch; say there were 3
git rebase -i head~3 # interactive rebase for the first 3 commits
# in the git rebase editor I leave the first entry on 'pick' and change the rest to 'squash'
git rebase master
git push -f # replace changes on remote branch

@cmoine
Copy link
Contributor Author

cmoine commented Sep 29, 2017

I find out my mistake with Git: I told that I woudl create a new PR :)

@cmoine cmoine closed this Sep 29, 2017
@cmoine
Copy link
Contributor Author

cmoine commented Sep 29, 2017

New PR: #585

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants