4

I have extended org.eclipse.ui.editors.text.TextEditor to implement a custom editor. For this editor, I have defined a marker type (org.eclipse.core.resources.markers extension point) and an annotation type (org.eclipse.ui.editors.annotationTypes extension point) to mark specific parts of code in my editor. I use a reconciler to update my annotation model.

Now I want to add a quick fix / quick assist feature. I simply want eclipse, to show a box with proposals, when I hover over an annotated part of the code and replace that part with a given string, when I click on a proposal. Just like the quick fix feature for the java editor.

So, what is the best way to implement this behavior?

I read about marker resolution generators and quick assist processors, but I'm still confused how it all works together...

I would be glad, if someone could point me to the right direction.

EDIT: From what I've understood so far, a MarkerResolutionGenerator is responsible for showing quick fixes in the problems view. To get quick fixes in the source viewer, I would have to set a QuickAssistAssistant for my SourceViewer and implement a QuickAssistProcessor which returns CompletionProposals. Is this the right way to do it?

EDIT2: I'm wondering if I need Markers at all, or only Annotations, I'm confused...

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

2 Answers2

4

I finally found out how to get Quick Fix to work for my editor.

I use the annotationTypes extension point to register my own annotation type and the 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.

Then I override getReconciler(...) to return a MonoReconciler with my own implementation of IReconcilingStrategy to create the annotations in its reconcile(...) method. And finally I override getQuickAssistAssistant(...) to return a QuickAssistAssistant with my own implementation of IQuickAssistProcessor. The computeQuickAssistProposals(...) method in the processor class computes the quick fix proposals which show up, when I press CTRL+1.

I don't create any Marker objects and don't use a MarkerResolutionGenerator, since the marker concept is much more heavyweight than using only annotations and the functionality which annotations provide fits my needs.

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

You have to register an extension to the extension point org.eclipse.ui.ide.markerResolution. This extension refers to a markerType (using the markerId), and also a resolution generator.

The latter component is responsible for calculating the possible fixes: it reads the marker, it can check the related files, etc., and creates marker resolution instances. These resolution instances basically process the erroneous files, and hopefully fix the original problem.

During marker resolution, you should not worry about removing the markers, as after the fix is executed, sometimes the validation would run again (e.g. during the build, or if no automatic validation is available, then manually - but it is not the task of the marker resolution to update the list of markers).

reprogrammer
  • 14,298
  • 16
  • 57
  • 93
Zoltán Ujhelyi
  • 13,788
  • 2
  • 32
  • 37
  • I did so, but the methods of my marker resolution generator are never invoked. I think this is the right way, if you have a Builder which manages markers on save and build, but I add Annotations to my AnnotationModel, because I just need error marking while typing. Or do I have to set something in my SourceViewerConfiguration to get the resolution generator to work? – Baris Akar Jan 21 '12 at 15:06
  • AFAIK Quick fixes are not registered to annotations but to markers. You can automatically create annotations from markers using the markerannotationspecification extension point. – Zoltán Ujhelyi Jan 21 '12 at 17:03
  • I'm now creating markers and adding MarkerAnnotations to my annotation model, but the quick fix is only available in the problems view. How do I get the quick fix to appear on mouse over in the source viewer? – Baris Akar Jan 23 '12 at 11:51
  • I'm sorry- I don't have any further ideas... Maybe if I will have time, I will try to look for more documentation/source code... – Zoltán Ujhelyi Jan 23 '12 at 14:30