如何为自定义eclipse编辑器实现快速修复/快速辅助? [英] How to implement Quick Fix / Quick Assist for custom eclipse editor?
问题描述
我已经扩展了 org.eclipse.ui.editors.text.TextEditor
来实现自定义编辑器。
对于此编辑器,我已经定义了一个标记类型( org.eclipse.core.resources.markers
扩展点)和注释类型( org.eclipse.ui.editors.annotationTypes
扩展点)来标记我编辑器中特定的代码部分。我使用调节器更新我的注释模型。
现在我要添加一个快速修复/快速辅助功能。当我点击提案时,当我将鼠标悬停在代码的注释部分并用给定的字符串替换该部分时,我只想要eclipse显示一个提案框。就像java编辑器的快速修复功能一样。
那么,实现这个行为的最好方法是什么?
我读了关于标记分辨率生成器和快速助理处理器,但我仍然困惑如何一起工作...
我会很高兴,如果有人可以指出我正确的方向。
编辑:从目前为止我已经了解到,一个 MarkerResolutionGenerator
负责在问题视图中显示快速修复。要在源查看器中快速修复,我必须为我的 SourceViewer
设置一个 QuickAssistAssistant
并实现一个 QuickAssistProcessor
返回 CompletionProposals
。
这是正确的方法吗?
EDIT2:我想知道是否需要标记
,或者只有注释
,我很困惑...
我终于找到了如何让Quick Fix为我的编辑工作。
我使用 annotationTypes
扩展点注册我自己的注释类型和 markerAnnotationSpecification
扩展点来指定外观。在我的自定义 SourceViewerConfiguration
class I override getAnnotationHover(...)
返回一个 DefaultAnnotationHover
object和 getTextHover(...)
返回一个 DefaultTextHover
对象,所以注释是显示在我的源浏览器中。
然后我覆盖 getReconciler(...)
返回一个 MonoReconciler
我自己执行 IReconcilingStrategy
在其调和(...)
方法中创建注释。最后,我覆盖 getQuickAssistAssistant(...)
返回一个 QuickAssistAssistant
与我自己的实现 IQuickAssistProcessor
。处理器类中的 computeQuickAssistProposals(...)
方法计算当我按CTRL + 1时显示的快速修订提案。
我不创建任何标记
对象,不要使用 MarkerResolutionGenerator
,因为标记概念比仅使用注释和注释提供的功能符合我的需求要重得多。
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 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.
这篇关于如何为自定义eclipse编辑器实现快速修复/快速辅助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!