Bug 528418

Summary: [code mining] Support for action CodeMining
Product: [Eclipse Project] Platform Reporter: Angelo ZERR <azerr>
Component: TextAssignee: Angelo ZERR <azerr>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, gautier.desaintmartinlacaze, Lars.Vogel, mistria
Version: 4.8Keywords: noteworthy
Target Milestone: 4.8 M5   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/115075
https://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=e8186dc22f970dae14d07ccb5341906955989f29
https://git.eclipse.org/r/115809
https://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=7af0e31a19e9566f7fb8819ed75278c6cf42265b
Whiteboard:
Bug Depends on: 527720, 529087    
Bug Blocks: 529316, 526969    

Description Angelo ZERR CLA 2017-12-11 08:29:58 EST
CodeMining provides the capability to draw content before a line. It should be cool if user could execute an action on click on mining.

Here some examples of action mining with Java Editor:

 * click on "n references" mining executes the JDT search references (like Ctrl+Shift+G) 
 * click on "n implementation" mining open the JDT Implementation dialog (like Ctrl+T)kind of events?)
 * click on "Run/Debug" icons (before a main method or @Test methods) execute the Java class.

To support this feature, ICodeMining should support:

 * hover mining: when mining is hovered, the label mining (or icons) must be displayed as hovered (like an hyperlink for label)
 * gives the capability to add an action with a new API like 

------------------------------------------
ICodeMining#addSelectionListener(CodeMiningSelectionListener listener)

ICodeMining#removeSelectionListener(CodeMiningSelectionListener listener)
------------------------------------------

Question: if we have addSelectionListener, it means that we have several actions to execute, is it a good idea? Perhaps we should provide an hover which displays list of available actions to execute (like Hyperlink)?
Comment 1 Mickael Istria CLA 2017-12-12 03:31:22 EST
+1.
Note that these workflows can already be implemented by placing MouseListeners in the `draw` method. It's not extremely straightforward, but it works ;)

(In reply to Angelo ZERR from comment #0)
>  * hover mining: when mining is hovered, the label mining (or icons) must be
> displayed as hovered (like an hyperlink for label)

I don't think we should give user the opportunity to tweak it. If they use an AbstractCodeMining, hover should just underline the label or icon for instance. Users shouldn't be requested to implement it manually.

>  * gives the capability to add an action with a new API like 
> ------------------------------------------
> ICodeMining#addSelectionListener(CodeMiningSelectionListener listener)
> ICodeMining#removeSelectionListener(CodeMiningSelectionListener listener)
> ------------------------------------------
> Question: if we have addSelectionListener, it means that we have several
> actions to execute, is it a good idea? Perhaps we should provide an hover
> which displays list of available actions to execute (like Hyperlink)?

Let's start smaller and minimize APIs there. The 'codeMiningSelected' action could simply be an (optional) method to implement in the ICodeMining implementation. Let's avoid creating specific listener, and start by assuming the provider of the CodeMining has the full control over the action, before implementing some extensibility we may not need.
For example, the `N implementations` codemining would implement a `codeMiningSelected()` method that would show the search result.
Comment 2 Angelo ZERR CLA 2017-12-30 06:47:10 EST
@Mickael, once you will accept https://bugs.eclipse.org/bugs/show_bug.cgi?id=529087 I will create a gerrit patch to support action. It will help more to discuss about this feature.

Please note that, I'm using this action support for:

 * inside the InlinedAnnotationDemo (now you can click on the colorized square to open the ColorDialog).
 * to Run/Debug Junit test 

See demo at https://bugs.eclipse.org/bugs/show_bug.cgi?id=529316
Comment 3 Eclipse Genie CLA 2018-01-08 17:15:23 EST
New Gerrit change created: https://git.eclipse.org/r/115075
Comment 5 Eclipse Genie CLA 2018-01-22 09:06:24 EST
New Gerrit change created: https://git.eclipse.org/r/115809
Comment 6 Angelo ZERR CLA 2018-01-22 09:10:42 EST
@Mickael, please review my N&N. Thanks!
Comment 8 Angelo ZERR CLA 2018-01-22 09:45:30 EST
Thanks @Lars, @Mickael for your review!