Bug 530825 - [code mining] Update CodeMinings with IJavaReconcilingListener
Summary: [code mining] Update CodeMinings with IJavaReconcilingListener
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.8   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.8 M7   Edit
Assignee: Angelo ZERR CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on: 531421
Blocks: 529316 529011 529127
  Show dependency tree
 
Reported: 2018-02-07 06:40 EST by Angelo ZERR CLA
Modified: 2018-04-05 17:31 EDT (History)
6 users (show)

See Also:
daniel_megert: pmc_approved+
noopur_gupta: review+


Attachments
Java CodeMining & preferences (2.40 MB, image/gif)
2018-02-21 10:24 EST, Angelo ZERR CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Angelo ZERR CLA 2018-02-07 06:40:18 EST
This issue is just to update JFace Platforme CodeMinings support inside Java Editor by using IJavaReconcilingListener feature: in other words update CodeMinings when compilation unit changed.

Please note this issue doesn't declare some Java CodeMining provider, so it will change nothing about the current Java Editor (StyledText continue to be fast if none Java CodeMinings are registered with extension point).
Comment 1 Eclipse Genie CLA 2018-02-07 06:43:14 EST
New Gerrit change created: https://git.eclipse.org/r/116845
Comment 2 Eclipse Genie CLA 2018-02-07 07:17:39 EST
New Gerrit change created: https://git.eclipse.org/r/116847
Comment 3 Angelo ZERR CLA 2018-02-07 07:58:24 EST
@Dani, @Sarika

Please review my simple gerrit patch which updates CodeMinings (if there are CodeMinings registered with extension point codeMiningProvider).

My gerrit patch doesn't affect the performance of Java Editor since there are none registered CodeMining providers.
Comment 4 Angelo ZERR CLA 2018-02-09 04:44:15 EST
@noopur is there any chance that you accept my gerrit patch. I need it for my other gerrit patch with CodeMining:

 * Java References/Implementations CodeMinings https://bugs.eclipse.org/bugs/show_bug.cgi?id=529127
 * JUnit Status/Run/Debug CodeMinings https://bugs.eclipse.org/bugs/show_bug.cgi?id=529316
 * Allow to show the type parameter names in method calls via inlined annotation support https://bugs.eclipse.org/bugs/show_bug.cgi?id=529011

Please note my gerrit patch on this issue doesn't affect performance of JDT Java Editor because CodeMinings is activated only if there one codemining provider registered.

@Mickael Istria and me are working on this performance problem with StyledText and here a well gerrit patch https://git.eclipse.org/r/#/c/116962/ which improves performance with big file like StyledText.java. It's not perfect again, but I have other ideas to improve StyledText.

Thanks for your review @noopur !
Comment 5 Noopur Gupta CLA 2018-02-09 05:12:49 EST
(In reply to Angelo ZERR from comment #4)
> @noopur is there any chance that you accept my gerrit patch. I need it for
> my other gerrit patch with CodeMining:

I don't think I will have time until M6 so I can't commit to looking at it. It will be good if someone else can do the review.

In general, it may be better if you create a new beta branch in jdt.ui and put all your changes in that. It will be easier to manage dependencies b/w patches and to test, review and push all the changes together.
Comment 6 Angelo ZERR CLA 2018-02-09 05:23:03 EST
> I don't think I will have time until M6 so I can't commit to looking at it. It will be good if someone else can do the review.

Ok thanks for your answer.

> In general, it may be better if you create a new beta branch in jdt.ui and put all your changes in that. It will be easier to manage dependencies b/w patches and to test, review and push all the changes together.

It should really fantastic if this gerit patch of this issue could be merged in M6. The gerit patch is very simple and there are none impact with performances.

If you accept this gerrit patch, I could create an external plugin outside JDT project which will provide my Java CodeMinings. Photon users could benefit with Java CodeMinings by installing my external plugin and we could benefit from feedback to know if my external plugin could be integrated inside the JDT project.

What do you think about this idea?
Comment 7 Noopur Gupta CLA 2018-02-09 05:29:33 EST
(In reply to Angelo ZERR from comment #6)
> What do you think about this idea?
Sounds good. I will try to get back to you on this Gerrit patch by next week. I hope that's fine.
Comment 8 Angelo ZERR CLA 2018-02-09 05:31:17 EST
> Sounds good. 

Cool!

> I will try to get back to you on this Gerrit patch by next week. I hope that's fine.

Yes sure! If my gerrit patch is included in Photon, it's perfect! Thanks!
Comment 9 Noopur Gupta CLA 2018-02-12 08:21:02 EST
This patch always adds a code mining reconcile listener to the CU editor which may not be required. The listener should be added only when code mining is enabled and other checks can also be added later. 

The implementation can be similar to SemanticHighlightingReconciler listener i.e. not part of the CompilationUnitEditor itself.
Comment 10 Angelo ZERR CLA 2018-02-12 08:56:46 EST
> This patch always adds a code mining reconcile listener to the CU editor which may not be required. The listener should be added only when code mining is enabled and other checks can also be added later. 


What is the problem with that? If there are none CodeMinings, listener does nothing. The call of updateCodeMinings does nothing.

To support your idea, we need to support in JFace Text Platform, listener when CodeMining providers is added, removed and activate and add/remove a "code mining reconcile listener" in this case. I'm afraid that it's a little hard. Today calling updateCodeMinings every time work for any case (when there are none CodeMining, when CodeMining will be added/removed).

@Mickael, what do you think about my comment? Do you think we need to support CodeMining listeners?
Comment 11 Noopur Gupta CLA 2018-02-13 07:34:10 EST
(In reply to Angelo ZERR from comment #10)
> > This patch always adds a code mining reconcile listener to the CU editor which may not be required. The listener should be added only when code mining is enabled and other checks can also be added later. 
> 
> 
> What is the problem with that? If there are none CodeMinings, listener does
> nothing. The call of updateCodeMinings does nothing.

This is to have a clean solution which avoids cluttering the internal CompilationUnitEditor class.

I haven't checked the code but a new reconcile listener similar to SemanticHighlightingReconciler with minimal checks (e.g. for the preference enabling the code minings feature) and functionality for the first cut should be fine here.
Comment 12 Mickael Istria CLA 2018-02-16 16:24:46 EST
(In reply to Noopur Gupta from comment #9)
> This patch always adds a code mining reconcile listener to the CU editor
> which may not be required. The listener should be added only when code
> mining is enabled. 

by "when code mining is enabled", you mean "when at least one code mining provider is enabled in preferences", don't you?


(In reply to Angelo ZERR from comment #10)
> Do you think we need to support CodeMining listeners?

My interpretation of Noopur's comment is more that we need a preference listener, and depending on whether code mining providers are enabled or not, we invoke CompilationUnitEditor.add/removeReconcilingListeners. This involves creating a "JavaCodeMiningIReconcilingListener implements IJavaReconcilingListener".
Noopur's hint about SemanticHighlightingManager is a good one, this class and its usages are probably the best examples to follow.
Comment 13 Angelo ZERR CLA 2018-02-19 11:32:21 EST
> My interpretation of Noopur's comment is more that we need a preference listener,

Ok I understand more. The question is which preference key we can use inside AbstractDecoratedTextEditor#handlePreferenceStoreChanged to track changed of codemining providers. With https://bugs.eclipse.org/bugs/show_bug.cgi?id=528728 I have tried to manage CodeMinings with a generic mean. So it was easy to refresh codemining, because the preference key was the same for the whole editor.

But it seems that you prefer managing CodeMining preferences inside JDT, for instance with the Java / Editor/ CodeMinings preference page:

----------------------
 -----  Java  -----
 [v] Show references
 [v] Show implementations
 [v] Show parameters of callee methods

 -----  JUnit  -----
 [v] Show status
 [ ] Show run icon
 [ ] Show debug icon
----------------------

How to store those preferences? I think the better solution is to have a preference key per "show" mining like this:

----------------------
java.codeminings.references=true
java.codeminings.implementations=true
java.codeminings.callee_methods=true
java.codeminings.junit.status=true
java.codeminings.junit.run=false
java.codeminings.junit.debug=false
----------------------

With this solution you can easily use IPeferenceStore#getBoolean to know if "java.codeminings.references" and/or "java.codeminings.implementations" managed by JavaCodeMiningProvider must be shown or not.

But the hard part is about which preferences key we must track to add/remove IJavaReconcilingListener. We could try to track the whole preferences key "java.codeminings.references", "java.codeminings.implementations", etc but it's not a generic mean since external plugin could define CodeMinings for the Java editor.

So I tell me, that we could have a non persistent preference like "java.codeminings.enabled" which is computed in the CodeMinings preference page by checking that there is at least one "show" which is checked.

The CompilationUnitEditor#handlePreferenceStoreChanged could track this non persistent preference "java.codeminings.enabled" to add/remove IJavaReconcilingListener which updates code minings. The codemining providers list should be recomputed again, so I think we should update too ISourceViewerExtension5 to add a new method:

--------------------------------------------------------
ISourceViewerExtension5#installCodeMinigProviders()
--------------------------------------------------------

which is today a private method inside SourceViewer#installCodeMinigProviders')

@Mickael, @Noopur what do you think about that?
Comment 14 Angelo ZERR CLA 2018-02-21 04:57:44 EST
@Mickael, @Noopur please see my new gerrit patch ay https://git.eclipse.org/r/#/c/116847/ which follows the same idea than semantic highlight manager. 

Please note my gerrit patch fails (compilation error) because it need this JFace Text gerrit patch https://git.eclipse.org/r/#/c/117806/
Comment 15 Sarika Sinha CLA 2018-02-21 08:21:25 EST
Do we really need preference for each ?
java.codeminings.references=true
java.codeminings.implementations=true
java.codeminings.callee_methods=true
java.codeminings.junit.status=true
java.codeminings.junit.run=false
java.codeminings.junit.debug=false

I think one preference to enable code mining in JDT editor should be enough, isn't it?
At most one for Java and one for JUnit I guess.
Comment 16 Angelo ZERR CLA 2018-02-21 08:28:48 EST
> Do we really need preference for each ?

IMHO I think it's good to to that. User can check which code minings he wishes to display in the Java Editor. For instance for JUnit, some user would like to show only status of test and other users would like to display status of test and the debug icon.

VSCode Java (https://marketplace.visualstudio.com/items?itemName=redhat.java) configures their references and implementations CodeLens with 2 preferences too:

-----------------------------------------------------------
java.referencesCodeLens.enabled : Enable/disable the references code lenses.
java.implementationsCodeLens.enabled : Enable/disable the implementations code lenses.
-----------------------------------------------------------
Comment 17 Mickael Istria CLA 2018-02-21 10:13:16 EST
I agree with Angelo. As a user, I'd like to disable the references count which I find not so profitable and taking a lot of space, but I'd love to get the parameter names, and the JUnit actions/reports for instance.
Comment 18 Sarika Sinha CLA 2018-02-21 10:20:57 EST
As a user I will like the flexibility, but then there should be a quick way to disable/enable all the Code Mining Preferences as well.
Comment 19 Angelo ZERR CLA 2018-02-21 10:24:38 EST
Created attachment 272792 [details]
Java CodeMining & preferences

@Sarika here a demo with my current work with Java CodeMining and preferences. This preference page gives the capability to enable/disable each CodeMining easily. Hope you will like it.
Comment 20 Sarika Sinha CLA 2018-02-21 10:32:49 EST
(In reply to Angelo ZERR from comment #19)
> Created attachment 272792 [details]
> Java CodeMining & preferences
> 
> @Sarika here a demo with my current work with Java CodeMining and
> preferences. This preference page gives the capability to enable/disable
> each CodeMining easily. Hope you will like it.

Thanks !!
Comment 21 Martin Lippert CLA 2018-03-05 09:59:24 EST
I would be highly interested in this and would love to implement my own code mining extension for the Java editor. Is there a chance to get this into Photon somehow? Anything I can help with?
Comment 22 Angelo ZERR CLA 2018-03-05 10:04:54 EST
> I would be highly interested in this and would love to implement my own code mining extension for the Java editor. Is there a chance to get this into Photon somehow? Anything I can help with?

Glad mining could interested you. If you wish to start implementing a Java JDT CodeMining (without applying this patch), I suggest you that you import in your workspace the 2 plugins from https://github.com/angelozerr/jdt-codemining

You can see an example at https://github.com/angelozerr/jdt-codemining/blob/master/org.eclipse.jdt.codemining/plugin.xml#L15

Hope it will help you.
Comment 23 Noopur Gupta CLA 2018-03-20 09:50:17 EDT
(In reply to Angelo ZERR from comment #14)
> @Mickael, @Noopur please see my new gerrit patch ay
> https://git.eclipse.org/r/#/c/116847/ which follows the same idea than
> semantic highlight manager. 
I have not tried the patch to see if it works as Sarika has already tested that. In the code review, I have made some changes in the patch like added some instanceof and null checks, fixed Javadocs, formatting, method names etc. The patch is good to go once the additional comment regarding preference prefix is handled.
Comment 25 Angelo ZERR CLA 2018-03-21 15:15:05 EDT
Thanks a lot @Noopur! It's a very great news, now anybody can register their own codemining provider for JDT Editor, it's a very cool news!

Do you know where I could write some doc "how to integrate codemining in Java Editor"? For instance I think it's important to speak about codemining preferences which must start with "java.codemining." to refresh the Java Editor when preferences changed 'Show, References, etc)
Comment 26 Stephan Herrmann CLA 2018-03-21 20:58:40 EDT
Sorry to spoil the party but this commit:

(In reply to Eclipse Genie from comment #24)
> Gerrit change https://git.eclipse.org/r/116847 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/
> ?id=1332a4312cbbf390f92cc692ec6eae2904899c43

seems to cause this failure in official builds:

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.1.0:compile (default-compile) on project org.eclipse.jdt.ui: Compilation failure: Compilation failure:
[ERROR] /opt/public/eclipse/builds/4I/gitCache/eclipse.platform.releng.aggregator/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java:[4330]
[ERROR] installCodeMinigProviders();
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] The method installCodeMinigProviders() is undefined for the type JavaEditor

See http://download.eclipse.org/eclipse/downloads/drops4/I20180321-2000/buildlogs/mb060_run-maven-build_output.txt
Comment 27 Noopur Gupta CLA 2018-03-22 01:42:34 EDT
(In reply to Stephan Herrmann from comment #26)
> Sorry to spoil the party but this commit:
> 
> (In reply to Eclipse Genie from comment #24)
> > Gerrit change https://git.eclipse.org/r/116847 was merged to [master].
> > Commit:
> > http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/
> > ?id=1332a4312cbbf390f92cc692ec6eae2904899c43
> 
> seems to cause this failure in official builds:
> 
> [ERROR] Failed to execute goal
> org.eclipse.tycho:tycho-compiler-plugin:1.1.0:compile (default-compile) on
> project org.eclipse.jdt.ui: Compilation failure: Compilation failure:
> [ERROR]
> /opt/public/eclipse/builds/4I/gitCache/eclipse.platform.releng.aggregator/eclipse.jdt.ui/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/JavaEditor.java:[4330]
> 
> [ERROR] installCodeMinigProviders();
> [ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^
> [ERROR] The method installCodeMinigProviders() is undefined for the type
> JavaEditor
> 
> See
> http://download.eclipse.org/eclipse/downloads/drops4/I20180321-2000/buildlogs/mb060_run-maven-build_output.txt
> 

This is due to bug 532703.
Comment 28 Noopur Gupta CLA 2018-03-22 02:00:21 EDT
(In reply to Angelo ZERR from comment #25)
> Thanks a lot @Noopur! It's a very great news, now anybody can register their
> own codemining provider for JDT Editor, it's a very cool news!
> 
> Do you know where I could write some doc "how to integrate codemining in
> Java Editor"? For instance I think it's important to speak about codemining
> preferences which must start with "java.codemining." to refresh the Java
> Editor when preferences changed 'Show, References, etc)

You can check the eclipse.platform.common repo to add Platform and JDT documentation.
Comment 29 Dani Megert CLA 2018-03-22 12:17:27 EDT
(In reply to Noopur Gupta from comment #28)
> (In reply to Angelo ZERR from comment #25)
> > Thanks a lot @Noopur! It's a very great news, now anybody can register their
> > own codemining provider for JDT Editor, it's a very cool news!
> > 
> > Do you know where I could write some doc "how to integrate codemining in
> > Java Editor"? For instance I think it's important to speak about codemining
> > preferences which must start with "java.codemining." to refresh the Java
> > Editor when preferences changed 'Show, References, etc)
> 
> You can check the eclipse.platform.common repo to add Platform and JDT
> documentation.

To be concrete, it should be added to the Programmer's Guide in
org.eclipse.platform.doc.isv and org.eclipse.jdt.doc.isv.
Comment 30 Dani Megert CLA 2018-03-23 11:01:01 EDT
Note that this added API after the freeze. Next time, please request approval from the PMC before submitting the change.