-
Notifications
You must be signed in to change notification settings - Fork 229
CodeMining: reuse existing inlined annotations when minings are unchanged #3580
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ | |
| import org.eclipse.core.runtime.Assert; | ||
|
|
||
| import org.eclipse.jface.internal.text.codemining.CodeMiningLineContentAnnotation; | ||
| import org.eclipse.jface.internal.text.codemining.CodeMiningLineHeaderAnnotation; | ||
|
|
||
| import org.eclipse.jface.text.BadLocationException; | ||
| import org.eclipse.jface.text.DocumentEvent; | ||
|
|
@@ -58,6 +59,7 @@ | |
| import org.eclipse.jface.text.Position; | ||
| import org.eclipse.jface.text.Region; | ||
| import org.eclipse.jface.text.TextPresentation; | ||
| import org.eclipse.jface.text.codemining.ICodeMining; | ||
| import org.eclipse.jface.text.source.Annotation; | ||
| import org.eclipse.jface.text.source.AnnotationPainter; | ||
| import org.eclipse.jface.text.source.IAnnotationModel; | ||
|
|
@@ -483,8 +485,15 @@ public void updateAnnotations(Set<AbstractInlinedAnnotation> annotations) { | |
| * @return the existing codemining annotation with the given position information and null | ||
| * otherwise. | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| public <T extends AbstractInlinedAnnotation> T findExistingAnnotation(Position pos) { | ||
| return findExistingAnnotation(pos, null); | ||
| } | ||
|
|
||
| /** | ||
| * @since 3.30 | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| public <T extends AbstractInlinedAnnotation> T findExistingAnnotation(Position pos, List<ICodeMining> minings) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible and/or better to implement the caching directly in this manager instead of expecting all providers to implement it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot for the very fast response. The Java implementation returns a I locally already started with a second Extension interface which allows to provide this information. But compatibility handling then got so complicated that I gave up. This pull request together with eclipse-jdt/eclipse.jdt.ui#2697 is much less complex and easier to follow. For sure, we move more complexity to the provider implementation. A simpler alternative approach could be the introduction of a subclass of What is your opinion here? In which direction should I go?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As I mentioned in the other ticket already, this approach is fundamentally broken and completely contradicts the usage of The use case of This is then all what's needed to let the caller know "keep whats currently used because I have nothing new (yet) for you"... Also otherwise how should the "manager" no when it is time to ask for something new? That's all what completable future is for!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @laeubi could you please take a look at eclipse-jdt/eclipse.jdt.ui@master...tobiasmelcher:eclipse.jdt.ui:wait_for_reconciler ? Are you proposing this approach? I added a Thread.sleep(3000) by intention to show a sceanrio where reconciliation takes a longer time. Here a screencast showing the JDT and Copilot code minings providing some results. java_reconciler_3_seconds_.mp4What is your opiniion? What would you propose? Should we trigger a redraw for each CompletableFuture separately? I think that we then get complaints that we trigger redraw too much often.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is not optimal and has some room for improvements but yes this is how it basically is supposed to work and correct.
If reconcilation takes really that long we would get much more complains, but yes its valid for investigation of course. One still might question if this really happens at all?
This is a very simple approach what might can be optimized in several ways I think, e.g. one might wait only a certain time (e.g. 100ms) for providers and then already perform an update with whats there. Then one slow provider will not block all others, a total timeout might be useful as well (e.g. if a provider takes > 10 seconds cancel it), but this also depends on how the providers work, for example if the document constantly changing (during typing) then maybe even the document positions become stale anyways.
It all depends a bit on how we define "break". I would assume copilote is showing things based on the document model. If that currently is reconciled it would mean it is not up-to date, so even if we can show the things faster they might be wrong / outdated. So do we want to show something fast, or something more correct?
For the matter of this topic, see above. In general it might be useful to reconsider what copilot does here and possibly offering some specialized support for "ghosttext" that do not interfere with code mining. For example we have similar for auto-completion already, where typing more reduces the list of recommendations. e.g. in this particular case the editor can do much of the work already without the need of the provider, so in your example
Such an approach, specially crafted to "inline code completion" would not need to retrigger all codemining providers.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Very good proposal, I like it. I can take a look but this takes some time for me. You can also take over here if you want.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why introducing a new API only for the Copilot plugin? I am not quite sure. You would then need to take over here. I will not do it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not quite yet, I just wanted to get some feedback.
Sure no one want to force you hear, I just wanted to mention it here because the problem itself has different angles and places where things can be improved independently.
Before you where fine to introduce new API as well... of course it is not for copilot plugin it would be for who ever wants to provide "ghos text" what would not be needing an AI at all (e.g. local variables, fields, whatever...)
No obligations here, I just wanted to mention it that the actual usage of codemining + copilot approach refreshing everything on every keypress might better be solved with a dedicated API. So in general I would say: Fix the immediate JDT issue as described, if its getting slow for copilot its a different topic and should not be your primary concern here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @laeubi and @mickaelistria I created a pull request for the JDT project eclipse-jdt/eclipse.jdt.ui#2698 which should solve the flickering issue. Could you please be so kind and review the code? Do you have contacts in the JDT team who could support me with my request?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the outcome of this discussion is great and the PR is good too. |
||
| if (fInlinedAnnotations == null) { | ||
| return null; | ||
| } | ||
|
|
@@ -496,6 +505,22 @@ public <T extends AbstractInlinedAnnotation> T findExistingAnnotation(Position p | |
| // Do nothing | ||
| } | ||
| } | ||
| if (minings == null) { | ||
| continue; | ||
| } | ||
| List<ICodeMining> existingMinings= null; | ||
| if (ann instanceof CodeMiningLineHeaderAnnotation lineHeader) { | ||
| existingMinings= lineHeader.getMinings(); | ||
| } else if (ann instanceof CodeMiningLineContentAnnotation lineContent) { | ||
| existingMinings= lineContent.getMinings(); | ||
| } | ||
| if (existingMinings != null && existingMinings.equals(minings) && ann.getPosition() != null && !ann.getPosition().isDeleted()) { | ||
| try { | ||
| return (T) ann; | ||
| } catch (ClassCastException e) { | ||
| // Do nothing | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the discussion shows I don't think anyone needs access to this data structure or should access it! This is even an internal class so no one should ever call any method on this outside the framework itself.