Eclipse Plugin Development: How to highlight syntax in texteditor?


Given a java method name, i want to highlight it in the TextEditor. I have reference to the texteditor in ITextEditor.


You can create an IMarker object on a file which the Java editor will show.

IFile file = ... file to mark

IMarker marker = file.createMarker(IMarker.TASK); 

marker.setAttribute(IMarker.CHAR_START, start);
marker.setAttribute(IMarker.CHAR_END, end);

I have used a task marker in this example, but you can use the org.eclipse.core.resources.markers extension point to define your own marker.

org.eclipse.ui.editors.markerAnnotationSpecification extension point can be used to define the colors and style used to show the markers.

The org.eclipse.ui.editors.markerUpdaters extension point can be used to define how markers are updated in an editor as the file is edited.

Answered By – greg-449

Answer Checked By – Terry (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.