2

I've written an eclipse editor for my own DSL. When an editor is opened or saved I check the contents and create problem markers for any syntax errors. The markers show up in my editor as expected, and also in the Problems view.

I've got an extension point org.eclipse.ui.ide.markerResolution and provide an implementation of IMarkerResolutionGenerator which creates resolutions for problem markers. This works fine; when I right click a problem in the Problems view the Quick Fix option shows in the context menu and works fine.

My editor extends SourceViewerConfiguration and I override getQuickAssistAssistant(), returning an extension of QuickAssistAssistant. This allows me to right click a problem in the editor and see the Quick Fix option in the menu.

I'd really like to get the quick fix resolutions to appear when I hover over the problem in the editor, just like in the java editor. Currently just the problem text appears in the tooltip. Is there a seperate hook into this or should it be covered in two quick fix hooks I've already implemented?

Qwerky
  • 18,217
  • 6
  • 44
  • 80
  • Assuming you actually have an `TextSourceViewerConfiguration`, have a look at `TextSourceViewerConfiguration.getTextHover(ISourceViewer, String)`... – Tonny Madsen May 16 '12 at 13:09
  • @TonnyMadsen - You assume correctly, and I override `getTextHover`. Might have a look at `ITextHoverExtension` and `ITextHoverExtension2` though. – Qwerky May 16 '12 at 13:38

1 Answers1

1

I had the same problem and found a solution for myself: How to implement Quick Fix / Quick Assist for custom eclipse editor?

From what I've understood, Markers show up in the Problems View and Annotations show up in the editor (on the ruler and on mouse hover).

I use the org.eclipse.ui.editors.annotationTypes extension point to register my own annotation type and the org.eclipse.ui.editors.markerAnnotationSpecification extension point to specify the look and feel. In my custom SourceViewerConfiguration class I override getAnnotationHover(...) to return a DefaultAnnotationHover object and getTextHover(...) to return a DefaultTextHover object, so the annotations are shown in my source viewer.

To create annotations, you could use org.eclipse.ui.texteditor.SimpleMarkerAnnotation, you can construct a SimpleMarkerAnnotation passing a marker object to the constructor. Then you need to add the annotation to the annotation model. You can use getAnnotationModel() on your SourceViewer and then addAnnotation(Annotation annotation, Position position) on the AnnotationModel. All annotations in the model will be shown in the editor.

You could also use org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel as your annotation model. Then you won't need to create annotation objects first, since AbstractMarkerAnnotationModel provides a method addMarkerAnnotation(IMarker marker).

Have a look at the IAnnotationModel interface.

Community
  • 1
  • 1
Baris Akar
  • 4,895
  • 1
  • 26
  • 54