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…
I finally found out how to get Quick Fix to work for my editor.
I use the
annotationTypesextension point to register my own annotation type and themarkerAnnotationSpecificationextension point to specify the look and feel. In my customSourceViewerConfigurationclass I overridegetAnnotationHover(...)to return aDefaultAnnotationHoverobject andgetTextHover(...)to return aDefaultTextHoverobject, so the annotations are shown in my source viewer.Then I override
getReconciler(...)to return aMonoReconcilerwith my own implementation ofIReconcilingStrategyto create the annotations in itsreconcile(...)method. And finally I overridegetQuickAssistAssistant(...)to return aQuickAssistAssistantwith my own implementation ofIQuickAssistProcessor. ThecomputeQuickAssistProposals(...)method in the processor class computes the quick fix proposals which show up, when I press CTRL+1.I don’t create any
Markerobjects and don’t use aMarkerResolutionGenerator, since the marker concept is much more heavyweight than using only annotations and the functionality which annotations provide fits my needs.