Skip to content

Commit fc3d22c

Browse files
CodeMining: reuse existing inlined annotations when minings are
unchanged Add getMinings() accessor methods to CodeMiningLineContentAnnotation and CodeMiningLineHeaderAnnotation to expose their mining lists. Enhance findExistingAnnotation() in InlinedAnnotationSupport to accept an optional minings parameter and compare existing annotations' minings with new ones. This allows reusing existing annotation instances when the mining content hasn't changed, avoiding unnecessary annotation recreation and improving performance. The change prevents flickering and reduces overhead by preserving annotation objects when only their position is being updated during reconciliation, but their actual mining data remains identical. #2786 (comment)
1 parent e15e9bf commit fc3d22c

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

bundles/org.eclipse.jface.text/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.jface.text
5-
Bundle-Version: 3.29.100.qualifier
5+
Bundle-Version: 3.30.0.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Export-Package:

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineContentAnnotation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,8 @@ public boolean isInVisibleLines() {
216216
public final boolean isAfterPosition() {
217217
return afterPosition;
218218
}
219+
220+
public List<ICodeMining> getMinings() {
221+
return fMinings;
222+
}
219223
}

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningLineHeaderAnnotation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,8 @@ public Consumer<MouseEvent> getAction(MouseEvent e) {
290290
public boolean isInVisibleLines() {
291291
return super.isInVisibleLines();
292292
}
293+
294+
public List<ICodeMining> getMinings() {
295+
return fMinings;
296+
}
293297
}

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ private void renderCodeMinings(Map<Position, List<ICodeMining>> groups, ISourceV
297297
CodeMiningMode mode= CodeMiningMode.createFor(minings);
298298

299299
// Try to find existing annotation
300-
AbstractInlinedAnnotation ann= fInlinedAnnotationSupport.findExistingAnnotation(pos);
300+
AbstractInlinedAnnotation ann= fInlinedAnnotationSupport.findExistingAnnotation(pos, minings);
301301
if (ann == null || !mode.annotationType.isInstance(ann)) {
302302
// The annotation doesn't exists or has wrong type => create a new one.
303303
boolean afterPosition= false;

bundles/org.eclipse.jface.text/src/org/eclipse/jface/text/source/inlined/InlinedAnnotationSupport.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.eclipse.core.runtime.Assert;
4444

4545
import org.eclipse.jface.internal.text.codemining.CodeMiningLineContentAnnotation;
46+
import org.eclipse.jface.internal.text.codemining.CodeMiningLineHeaderAnnotation;
4647

4748
import org.eclipse.jface.text.BadLocationException;
4849
import org.eclipse.jface.text.DocumentEvent;
@@ -58,6 +59,7 @@
5859
import org.eclipse.jface.text.Position;
5960
import org.eclipse.jface.text.Region;
6061
import org.eclipse.jface.text.TextPresentation;
62+
import org.eclipse.jface.text.codemining.ICodeMining;
6163
import org.eclipse.jface.text.source.Annotation;
6264
import org.eclipse.jface.text.source.AnnotationPainter;
6365
import org.eclipse.jface.text.source.IAnnotationModel;
@@ -483,8 +485,15 @@ public void updateAnnotations(Set<AbstractInlinedAnnotation> annotations) {
483485
* @return the existing codemining annotation with the given position information and null
484486
* otherwise.
485487
*/
486-
@SuppressWarnings("unchecked")
487488
public <T extends AbstractInlinedAnnotation> T findExistingAnnotation(Position pos) {
489+
return findExistingAnnotation(pos, null);
490+
}
491+
492+
/**
493+
* @since 3.30
494+
*/
495+
@SuppressWarnings("unchecked")
496+
public <T extends AbstractInlinedAnnotation> T findExistingAnnotation(Position pos, List<ICodeMining> minings) {
488497
if (fInlinedAnnotations == null) {
489498
return null;
490499
}
@@ -496,6 +505,22 @@ public <T extends AbstractInlinedAnnotation> T findExistingAnnotation(Position p
496505
// Do nothing
497506
}
498507
}
508+
if (minings == null) {
509+
continue;
510+
}
511+
List<ICodeMining> existingMinings= null;
512+
if (ann instanceof CodeMiningLineHeaderAnnotation lineHeader) {
513+
existingMinings= lineHeader.getMinings();
514+
} else if (ann instanceof CodeMiningLineContentAnnotation lineContent) {
515+
existingMinings= lineContent.getMinings();
516+
}
517+
if (existingMinings != null && existingMinings.equals(minings) && ann.getPosition() != null && !ann.getPosition().isDeleted()) {
518+
try {
519+
return (T) ann;
520+
} catch (ClassCastException e) {
521+
// Do nothing
522+
}
523+
}
499524
}
500525
return null;
501526
}

0 commit comments

Comments
 (0)