Bug 532091 - [code mining] Don't draw minings which are cancelled
Summary: [code mining] Don't draw minings which are cancelled
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.8   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.8 M7   Edit
Assignee: Angelo ZERR CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2018-03-06 18:06 EST by Angelo ZERR CLA
Modified: 2018-04-05 17:25 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Angelo ZERR CLA 2018-03-06 18:06:57 EST
When codemining is updated quickly and resolve of codemining can takes some (little) time, codemining can flicker because sometimes the new mining is not resolved although the old mining is resolved.

This problem comes from that ICodeMining#isResolved() returns true even if future throw an error (ex: a cancel interrupted exception). In this case the mining label is null and a blank line is drawn (because label is null) (see CodeMiningLineHeaderAnnotation#draw)
Comment 1 Eclipse Genie CLA 2018-03-06 18:10:46 EST
New Gerrit change created: https://git.eclipse.org/r/118829
Comment 2 Angelo ZERR CLA 2018-03-12 09:44:00 EDT
@Mickael, could your review my gerrit patch please.
Comment 3 Eclipse Genie CLA 2018-03-22 14:20:06 EDT
New Gerrit change created: https://git.eclipse.org/r/120005
Comment 4 Angelo ZERR CLA 2018-03-22 14:23:01 EDT
@Mickael, I have redone a new gerrit patch at https://git.eclipse.org/r/120005

I have renamed the issue but I need it to fix https://github.com/angelozerr/jdt-codemining/issues/1
Comment 6 Lars Vogel CLA 2018-03-22 15:51:25 EDT
Thanks, Angelo.
Comment 7 Mickael Istria CLA 2018-03-22 16:01:15 EDT
This introduce an API addition ( isResolutionFailed ). Is this something still allowed directly in M7? Also, as it's an API, I think we should work on finding a better name as the proposed on sounds a bit awkward compared to usual conventions. We should also investigate whether we do actually need this method or whether some deeper fix can't be found (why would the codemining require to expose the state of resolution? Why making a difference between a failed resolution and an incomplete/wip resolution? Do we really need a public state for a failure?...)
Comment 8 Lars Vogel CLA 2018-03-22 16:08:55 EDT
(In reply to Mickael Istria from comment #7)
> This introduce an API addition ( isResolutionFailed ). Is this something
> still allowed directly in M7? Also, as it's an API, I think we should work
> on finding a better name as the proposed on sounds a bit awkward compared to
> usual conventions. We should also investigate whether we do actually need
> this method or whether some deeper fix can't be found (why would the
> codemining require to expose the state of resolution? Why making a
> difference between a failed resolution and an incomplete/wip resolution? Do
> we really need a public state for a failure?...)

I used API tooling, cleaned twice the WS and did not see any API error. Do you see an API error? In this case we need to revert and ask the PMC for permission.

As you also have other concerns I revert the patch so that Angelo can work on your feedback.
Comment 9 Eclipse Genie CLA 2018-03-22 16:10:11 EDT
New Gerrit change created: https://git.eclipse.org/r/120014
Comment 11 Eclipse Genie CLA 2018-03-22 16:10:16 EDT
New Gerrit change created: https://git.eclipse.org/r/120015
Comment 12 Lars Vogel CLA 2018-03-22 16:10:29 EDT
https://git.eclipse.org/r/#/c/120015/ contains the original change from Angelo.
Comment 13 Mickael Istria CLA 2018-03-22 16:17:12 EDT
(In reply to Lars Vogel from comment #8)
> I used API tooling, cleaned twice the WS and did not see any API error.

Are you using the API-frozen version (M6) as API baseline? I believe it's necessary to get some feedback from API Tools, but it can probably also lead to false-positive during API Freeze like this.

I think this whole story relates to bug 532679 too: if we don't try to "prepare" the empty area, it may be enough to stick with the isResolved() method.
Looking at the original description "In this case the mining label is null and a blank line is drawn" -> so why trying to redraw a line case label is null? Can't we just assume that a null mining is equivalent to not resolved?
Comment 14 Lars Vogel CLA 2018-03-22 16:32:46 EDT
(In reply to Mickael Istria from comment #13)
> Are you using the API-frozen version (M6) as API baseline? 

I'm using our latest 4.7 release.
Comment 15 Mickael Istria CLA 2018-03-22 16:51:03 EDT
(In reply to Lars Vogel from comment #14)
> I'm using our latest 4.7 release.

Ok, it explains why API Tools don't complain: version was bumped since 4.7 so additions are permitted. During API Freeze, it may be better to have the last milestone as baseline (so it compares with what's supposed to be frozen), but it may also report some need to bump version for internal stuff which would be false-positive... So it's a bit hard to get an automated behavior that works well in the IDE. The "official" build has a magic comparator which can help here, but good luck if you want to use it locally...
Comment 16 Angelo ZERR CLA 2018-03-22 18:30:14 EDT
> I think this whole story relates to bug 532679 too: if we don't try to "prepare" the empty area, it may be enough to stick with the isResolved() method.

This bug uses fResolvedMinings which should be filled only with resolved mining, but it's not true. Today fResolvedMinings can be filled with mining which can be cancelled, which provides the problem with "no command" text is displayed (case of mining is resolved and label is null).no

It causes 2 problems:

 * flicking of codemining which display "no command" sometimes (case of mining which canceled) and the mining label.
 * no the possibility to avoid drawing the mining.

A mining draw content with label, BUT it can draw other thing (like colorized square). In this case of colorized sqare, label is null. label is null before the execution of the CompletableFuture and after if CompletableFuture  was canceled. So how to distinguish those 2 cases?

My gerrit patch distinguish the case of mining was resolved (CompletableFuture was done with or without error) and resolved with failed (only when error). When resolved with failed was done, the mining must not be drawn and fResolvedMinings  must not to be updated. The fResolvedMinings  must keep the last mining which was resolved with none error.


To reproduce the problem easily, you can add at https://github.com/angelozerr/jdt-codemining/blob/master/org.eclipse.jdt.codemining/src/org/eclipse/jdt/internal/ui/javaeditor/codemining/JavaReferenceCodeMining.java#L57

----------------------------------------------------
if (true) throw new CancellationException();
----------------------------------------------------

which emulates a cancel of mining. You will see "no command" which is diplayed. fResolvedMinings  is updated with this label mining because mining is resolved (but have errore).


So my gerrit patch fix those 2 problems and if it accepted, I could support https://github.com/angelozerr/jdt-codemining/issues/1 easily (just CancellationException when refCount == 0).

Hope you will understand my explanation.
Comment 17 Angelo ZERR CLA 2018-03-23 08:01:39 EDT
@Mickael, I'm sorry to insist, but I think my gerrit patch provides a better support for mining:

 *  in term of bug "no command" can be displayed if mining is canceled and drawn together.
 * in term of performance: we don't try to redraw a mining which was canceled
 * in term of functionnality: you can ignore the draw of mining by cancelling the mining in the resolve. I'm using this idea to not draw "0 references" https://github.com/angelozerr/jdt-codemining/issues/1

I hope you will understand my explanation.
Comment 18 Mickael Istria CLA 2018-03-23 11:22:31 EDT
(In reply to Angelo ZERR from comment #16)
> which provides the problem with "no command" text is
> displayed

I don't think this is a desired behavior for end user. If there is no command, for whatever reason, the proper thing to do is to not show anything. If there is a bug or something else that prevents the command from being resolved, it's better to just log it than to pollute user's editor.

> A mining draw content with label, BUT it can draw other thing (like
> colorized square). In this case of colorized sqare, label is null. label is
> null before the execution of the CompletableFuture and after if
> CompletableFuture  was canceled. So how to distinguish those 2 cases?

We could consider the "label is null" case as not resolved, and distinguish it from the "label is empty". To draw a square with color, the mining could return empty string or "\u00A0" as label when ready to draw to toggle enablement, and override the size as best for it.

I really believe it's important for the maintainability of the API to not add a plethora of state methods, and to use existing one as much as possible.

> You will see "no command" which is diplayed.

As a end-user, I don't want to see this.
As a plugin developer, I do not want to pollute the end-user editor with a bug of mine.
As a plugin developer, I want the error from my mining to be logged in the regular log.
As a plugin developer, I want the error on end-user IDE to be logged in the usual log so the error reporting features can be used by end-user to notify of the bug.
Comment 19 Eclipse Genie CLA 2018-03-23 17:24:34 EDT
New Gerrit change created: https://git.eclipse.org/r/120110
Comment 20 Angelo ZERR CLA 2018-03-23 17:48:00 EDT
@Mickael, please see my new gerrit patch https://git.eclipse.org/r/120110 where I have tried to follow your idea with label (see ICodeMining#getLabel()) for explanation). Hope you will like it.
Comment 22 Angelo ZERR CLA 2018-03-25 10:06:22 EDT
Thanks a lot @Karsten for your review and merge my gerrit patch!

@Mickael, hope it will be OK with this merge of my gerrit patch.

@Lars, you can reinstall jdt codemining and use this merged gerit patch and retry https://github.com/angelozerr/jdt-codemining/issues/1 (if it works, please close it). Thanks!
Comment 23 Angelo ZERR CLA 2018-04-03 12:32:15 EDT
I reopen the bug because there is a little bug when you have several minings and label is empty:

For instance if you have 
 * mining1 with label =""
 * mining2 with label="references 2"

It displays:

-------------------
 | references 2
-------------------

instead of displaying 

-------------------
references 2
-------------------

(without pipe)
Comment 24 Eclipse Genie CLA 2018-04-03 12:41:55 EDT
New Gerrit change created: https://git.eclipse.org/r/120651
Comment 25 Angelo ZERR CLA 2018-04-03 12:44:11 EDT
@Lars, please review my gerrit https://git.eclipse.org/r/120651 (which is basic). I have seen this problem with your screenshot with JUnit code mining (which starts with '|' because test method have 0 references). Thanks!
Comment 27 Angelo ZERR CLA 2018-04-03 12:57:42 EDT
Thanks @Mickael!