Skip to content

Commit 1c3ad70

Browse files
Ensure code minings are rendered when editor is initially opened
Add a null check for the `support` field in the `AbstractInlinedAnnotation` class to prevent `NullPointerException` when the `isInVisibleLines` method is called. This issue occurs because `support` may not be initialized when the editor is first opened, causing code minings to not render initially.
1 parent 62f3974 commit 1c3ad70

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,17 @@ private void updateCodeMinings() {
145145
IProgressMonitor monitor= fMonitor;
146146
// Collect the code minings for the viewer
147147
getCodeMinings(fViewer, fCodeMiningProviders, monitor).thenAccept(symbols -> {
148-
// check if request was canceled.
149-
monitor.isCanceled();
150-
// then group code minings by lines position
151-
Map<Position, List<ICodeMining>> groups= groupByLines(symbols, fCodeMiningProviders);
152-
// resolve and render code minings
153-
renderCodeMinings(groups, fViewer, monitor);
148+
try {
149+
// check if request was canceled.
150+
monitor.isCanceled();
151+
// then group code minings by lines position
152+
Map<Position, List<ICodeMining>> groups= groupByLines(symbols, fCodeMiningProviders);
153+
// resolve and render code minings
154+
renderCodeMinings(groups, fViewer, monitor);
155+
} catch (Throwable e) {
156+
logCodeMiningProviderException(e);
157+
throw e;
158+
}
154159
});
155160
}
156161

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected AbstractInlinedAnnotation(Position position, ISourceViewer viewer) {
9393
protected AbstractInlinedAnnotation(Position position, ISourceViewer viewer, Consumer<MouseEvent> onMouseHover, Consumer<MouseEvent> onMouseOut, Consumer<MouseEvent> onMouseMove) {
9494
super(TYPE, false, ""); //$NON-NLS-1$
9595
this.position= position;
96+
this.fViewer= viewer;
9697
this.onMouseHover= onMouseHover;
9798
this.onMouseOut= onMouseOut;
9899
this.onMouseMove= onMouseMove;
@@ -248,6 +249,9 @@ void setSupport(InlinedAnnotationSupport support) {
248249
* otherwise.
249250
*/
250251
protected boolean isInVisibleLines() {
252+
if (support == null) {
253+
return true; // support not yet available, we have to be optimistic
254+
}
251255
return support.isInVisibleLines(getPosition().getOffset());
252256
}
253257

@@ -272,6 +276,9 @@ boolean isFirstVisibleOffset(int widgetOffset, ITextViewer viewer) {
272276
* otherwise.
273277
*/
274278
protected boolean isInVisibleLines(int offset) {
279+
if (support == null) {
280+
return true; // support not yet available, we have to be optimistic
281+
}
275282
return support.isInVisibleLines(offset);
276283
}
277284

0 commit comments

Comments
 (0)