Bug 527515 - [code mining] Add CodeMining support in SourceViewer
Summary: [code mining] Add CodeMining support in SourceViewer
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.8   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.8 M5   Edit
Assignee: Angelo ZERR CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation, noteworthy
: 501546 (view as bug list)
Depends on: 527675 527720
Blocks: 526969 528419
  Show dependency tree
 
Reported: 2017-11-20 11:06 EST by Angelo ZERR CLA
Modified: 2018-04-05 17:31 EDT (History)
6 users (show)

See Also:


Attachments
Code Mining demo (347.01 KB, image/gif)
2017-11-20 13:00 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 2017-11-20 11:06:44 EST
This bug is the first iteration of CodeMining contribution of https://bugs.eclipse.org/bugs/show_bug.cgi?id=526969.

It provides basic support for CodeMining with SourceViewer:

 * an ICodeMiningProvider API to retrieve list of code minings which are resolved or not.
 * an ICodeMiningResolver API to resolve code mining.
 * an new ISourceViewerExtension5 API to configure code minings and run it.

This contribution draw code minings with Annotation (by using AnnotationPainter) and line spacing of line (by implementings new APY StyledTextLineSpacingProvider).
Comment 1 Eclipse Genie CLA 2017-11-20 12:18:22 EST
New Gerrit change created: https://git.eclipse.org/r/111912
Comment 2 Angelo ZERR CLA 2017-11-20 13:00:39 EST
Created attachment 271562 [details]
Code Mining demo

Here a demo with the CodeMiningDemo that you can find in the gerrit patch.

I have done a lot of choice and try to comment the most possible, but I think it's not perfect. I'm aware to change anything!

Please note that it's the first iteration of Code Mining, there are another improvement to do in another gerrit patches (extension point, custom renderer, etc).

If you need some more explanation, don't hesite to tell me.

I have created an project org.eclipse.jface.text.examples to set the Code Mining demo, but I have not done pom.xml, etc. I wanted to set the demo in my gerrit patch (@Mickael please help me with pom.xml, build.properties, etc with this new project)

@Dani, @Mickael any feedback are welcome! And if you can, please help me with contribution. Thanks!
Comment 3 Mickael Istria CLA 2017-11-30 02:40:45 EST
*** Bug 501546 has been marked as a duplicate of this bug. ***
Comment 4 Pascal Rapicault CLA 2017-11-30 09:28:22 EST
A couple questions:
- Will there be any restrictions on the SourceViewers that can benefit from it?
- are line number of the underlying document touched? I assuem not?
- Is it possible to edit content in a code mining section?
Comment 5 Mickael Istria CLA 2017-11-30 09:46:59 EST
(In reply to Pascal Rapicault from comment #4)
> - Will there be any restrictions on the SourceViewers that can benefit from
> it?

The SourceViewers would need to implement ISourceViewerExtension5 ( https://git.eclipse.org/r/#/c/111912/1/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension5.java ) . The "default"  SourceViewer most editors do rely on will implement this interface ( https://git.eclipse.org/r/#/c/111912/1/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java )

> - are line number of the underlying document touched? I assuem not?

Nope, see bug 527675. The underline implementation only affects drawing by "shifting" the drawing of actual text of the necessary dx/dy to let the CodeMining be drawn in the created space.
But the underlying text and document isn't modified at all. So would be the line numbers.

> - Is it possible to edit content in a code mining section?

The proposed API in SourceViewer doesn't include that at the moment. And I think it would be too early to introduce it and it would better be done later.
But as it's all about drawing, I belive there wouldn't be too much of an issue with drawing editable content.
Comment 6 Mickael Istria CLA 2017-12-01 01:42:10 EST
@Angelo: do you see a possible relationship between the CodeMinungManager and a Reconcilier? Ie could CMM be a specific reconcilier?
Comment 7 Angelo ZERR CLA 2017-12-01 10:07:15 EST
> @Angelo: do you see a possible relationship between the CodeMinungManager and a Reconcilier? Ie could CMM be a specific reconcilier?

My idea is that CodeMiningManager should be host in an internal package and after we have ISourceViewerExtension5  like this:

----------------------------------------------------
public interface ISourceViewerExtension5 {

	/**
	 * Update minings
	 */
	void updateCodeMinings()

	/**
	 * Register the code mining providers.
	 * 
	 * @param codeMiningProviders the code mining providers
	 */
	void setCodeMiningProviders(ICodeMiningProvider[] codeMiningProviders);

}
----------------------------------------------------

With that, we can execute codemining manager like we wish:

 * with generic editor, just implement a reconciler which call  ISourceViewerExtension5#updateCodeMinings();

 * with JDT implements an org.eclipse.jdt.internal.ui.text.java.IJavaReconcilingListener and execute ISourceViewerExtension5#updateCodeMinings(); in reconciled method:

----------------------------------------------------
@Override
public void reconciled(CompilationUnit ast, boolean forced, IProgressMonitor progressMonitor) {
		((ISourceViewerExtension5)viewer)updateCodeMinings();
} 
----------------------------------------------------

like I had done with my CodeLens & JDT POC https://github.com/angelozerr/codelens-eclipse/blob/master/org.eclipse.codelens.jdt/src/org/eclipse/codelens/jdt/internal/JavaCodeLensController.java#L55

I'm waiting for https://bugs.eclipse.org/bugs/show_bug.cgi?id=527720 to do a new gerrit patch with this idea. In this gerrit patch, I would like too configure ICodeMiningProvider with SourceViewerConfiguration#getCodeMiningProviders(ISourceViewer sourceViewer) exactly like getHyperlinkDetectors.

In a an another bugs, I will provide an extension point for ICodeMiningProvider with TextSourceViewerConfiguration#getCodeMiningProviders(ISourceViewer sourceViewer) & SourceViewerConfiguration#getCodeMiningProviderTargets(ISourceViewer  sourceViewer) which will return Map<String, IAdaptable> exactly like hyperlink.
Comment 8 Eclipse Genie CLA 2017-12-11 06:29:18 EST
New Gerrit change created: https://git.eclipse.org/r/113149
Comment 9 Angelo ZERR CLA 2017-12-11 06:34:58 EST
@Mickael please review my gerrit patch https://git.eclipse.org/r/#/c/113149 which provides public API for codemining with ISourceViewerExtension5.java
Comment 11 Eclipse Genie CLA 2017-12-13 13:24:22 EST
New Gerrit change created: https://git.eclipse.org/r/113349
Comment 12 Angelo ZERR CLA 2017-12-13 13:32:19 EST
@Mickael, please review my gerrit patch https://git.eclipse.org/r/113349 for N&N

Thanks!
Comment 14 Angelo ZERR CLA 2017-12-14 06:31:41 EST
Thanks @Mickael for having reviewed my N&N!
Comment 15 Angelo ZERR CLA 2017-12-15 07:59:43 EST
@Mickael I think we can close this issue?
Comment 16 Mickael Istria CLA 2017-12-15 10:28:54 EST
Thanks Angelo.