Reputation: 869
I'm trying to write a custom text editor with a reconciler that will update the AST and create markers for the errors, if there are any. I managed to add markers that show up in the left ruler of the editor and in the problems view. However, I also want those errors to be underlined in the text. That doesn't work. None of the text is underlined. If I double click on one of the errors in the problem view however, the corresponding text in the text editor is selected. As far as I understand, I need to add an annotation in addition to the marker. This is what I have tried so far:
final IResource resource = ResourceUtil.getResource(getEditorInput());
final IMarker marker = resource.createMarker("com.test.myproblemmarker");
marker.setAttribute(IMarker.MESSAGE, "hello");
marker.setAttribute(IMarker.CHAR_START, 2);
marker.setAttribute(IMarker.CHAR_END, 10);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
final IDocumentProvider idp = getDocumentProvider();
final IDocument document = idp.getDocument(getEditorInput());
final IAnnotationModel iamf = idp.getAnnotationModel(getEditorInput());
final SimpleMarkerAnnotation ma = new SimpleMarkerAnnotation("org.eclipse.ui.workbench.texteditor.error", marker);
ma.setText("hello");
iamf.connect(document);
iamf.addAnnotation(ma, new Position(2, 8));
ma.update();
iamf.disconnect(document);
ma.update();
The relevant parts from plugin.xml
:
<extension id="com.test.problemmarker" point="org.eclipse.core.resources.markers" name="A Problem">
<super type="org.eclipse.core.resources.problemmarker"/>
<super type="org.eclipse.core.resources.textmarker"/>
<persistent value="true"/>
</extension>
<extension point="org.eclipse.ui.editors.markerAnnotationSpecification" id="myannotationspecification" name="MyAnnotation">
<specification
annotationType="com.test.problemannotation"
label="MyAnnotation"
icon="icons/icon16x16.png"
overviewRulerPreferenceKey="clruler"
overviewRulerPreferenceValue="true"
colorPreferenceKey="clcolor"
colorPreferenceValue="255,0,0"
textPreferenceKey="cltext"
textPreferenceValue="true"
verticalRulerPreferenceKey="clvertical"
verticalRulerPreferenceValue="true"
textStylePreferenceKey="clstyle"
textStylePreferenceValue="UNDERLINE"
presentationLayer="4">
</specification>
</extension>
<extension point="org.eclipse.ui.editors.annotationTypes">
<type
markerSeverity="2"
super="org.eclipse.ui.workbench.texteditor.error"
name="com.test.problemannotation"
markerType="com.test.problemmarker"/>
</extension>
The custom text editor inherits from TextEditor
and the reconciler is a MonoReconciler
. Seems like a pretty standard setup, when I look at existing editor / reconciler implementations. I appreciate any help!
Upvotes: 2
Views: 515
Reputation: 869
Ok, I was able to fix it myself. The problem was, that I set my own preference store in the constructor of the TextEditor
subclass:
setPreferenceStore(MyPlugin.getDefault().getPreferenceStore());
I set a few breakpoints in the AnnotationPainter
class and realized that all
annotations were disabled. When I removed this line from the editor, the annotations appeared.
I also noticed that it is sufficient to just create a marker. A corresponding annotation will be added automatically.
Upvotes: 2