创建带有文本悬停的 Eclipse 插件

2022-01-16 00:00:00 eclipse-plugin java

我想做一个 Eclipse 插件(文本编辑器).我会阅读"光标下的文本并显示取决于文本的动态生成悬停.现在我的问题是我不知道如何阅读文本并添加"悬停.

I would like to make a Eclipse plugin (text editor). I would "read" the text under the cursor and show a dynamical generated hover that depends on the text. Now I have the problem that I don't know how I can read the text and "add" the hover.

这是我的第一个 Eclipse 插件,所以我很高兴能得到每一个提示.

It's my first Eclipse Plugin so I am happy for each tip I can get.

我想将它集成到默认的 Eclipse Java 编辑器中.我曾尝试使用编辑器模板创建一个新的 plugin,但我认为这是错误的方式.

I'd like to integrate it into the default Eclipse Java editor. I have tried to create a new plugin with a editor template but I think it is the wrong way.

上次

来自 PKeidel 的答案正是我想要的 :)

The answer from PKeidel is exactly what I'm looking for :)

感谢 PKeidel

推荐答案

你的错是你创建了一个全新的编辑器,而不是为现有的 Java 编辑器创建一个插件.插件将通过 extension points 激活.在您的情况下,您必须使用 org.eclipse.jdt.ui.javaEditorTextHovers 更多....

Your fault is that you created a completly new Editor instead of a plugin for the existing Java Editor. Plugins will be activated via extension points. In your case you have to use org.eclipse.jdt.ui.javaEditorTextHovers more....

<plugin>
   <extension
         point="org.eclipse.jdt.ui.javaEditorTextHovers">
      <hover
            activate="true"
            class="path.to_your.hoverclass"
            id="id.path.to_your.hoverclass">
      </hover>
   </extension>

</plugin>


class 参数保存实现 IJavaEditorTextHover 的类的路径.

public class LangHover implements IJavaEditorTextHover
{
    @Override
    public String getHoverInfo(ITextViewer textviewer, IRegion region)
    {
         if(youWantToShowAOwnHover)
           return "Your own hover Text goes here"";
         return null; // Shows the default Hover (Java Docs)
    }
}

应该这样做;-)

相关文章