如何在 Eclipse RCP 中实现内容辅助文档弹出窗口

发布于 2024-07-21 06:29:59 字数 935 浏览 3 评论 0原文

我已经实现了自己的编辑器并为其添加了代码完成功能。 我的内容助手在源查看器配置中注册如下:

public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
    if (assistant == null) {
        assistant = new ContentAssistant();
        assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
        assistant.setContentAssistProcessor(getMyAssistProcessor(),
                MyPartitionScanner.DESIRED_PARTITION_FOR_MY_ASSISTANCE);
        assistant.enableAutoActivation(true);
        assistant.setAutoActivationDelay(500);
        assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
        assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
    }
    return assistant;
}

当我在所需分区内按 Ctrl + SPACE 时,将出现完成弹出窗口并按预期工作。

这是我的问题.. 如何实现/注册出现在完成弹出窗口旁边的文档弹出窗口? (例如在java编辑器中)

I have implemented my own editor and added a code completion functionality to it. My content assistant is registered in source viewer configuration like this:

public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
    if (assistant == null) {
        assistant = new ContentAssistant();
        assistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
        assistant.setContentAssistProcessor(getMyAssistProcessor(),
                MyPartitionScanner.DESIRED_PARTITION_FOR_MY_ASSISTANCE);
        assistant.enableAutoActivation(true);
        assistant.setAutoActivationDelay(500);
        assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);
        assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
    }
    return assistant;
}

When I press Ctrl + SPACE inside the desired partition, the completion popup appears and works as expected.

And here's my question.. How do I implement/register a documentation popup that appears next to completion popup? (For example in java editor)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笨死的猪 2024-07-28 06:29:59

好吧,

我自己回答这个问题;-)

你必须将此行添加

assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));

到上面的配置中。 然后,在创建 CompletionProposals 时,构造函数的第八个(最后一个)名为 additionalProposalInfo 的参数是文本,它将显示在文档弹出窗口中。

new CompletionProposal(replacementString,
                          replacementOffset,
                          replacementLength,
                          cursorPosition,
                          image,
                          displayString,
                          contextInformation,
                          additionalProposalInfo);

有关更多信息,请参阅这里

很简单,不是吗……如果你知道怎么做的话;)

Well,

I'll answear the question myself ;-)

You have to add this line

assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));

to the configuration above. Then when creating CompletionProposals, the eighth (last) parameter called additionalProposalInfo of the constructor is the text, which will be shown in the documentation popup.

new CompletionProposal(replacementString,
                          replacementOffset,
                          replacementLength,
                          cursorPosition,
                          image,
                          displayString,
                          contextInformation,
                          additionalProposalInfo);

More information about can be found here.

Easy, isn't it.. if you know how to do it ;)

猫烠⑼条掵仅有一顆心 2024-07-28 06:29:59

对于样式信息框(就像 JDT 中一样)。

样式附加信息


  • DefaultInformationControl 实例需要接收一个 HTMLTextPresenter
  • import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
    
    public class MyConfiguration extends SourceViewerConfiguration {
    
    
        [...]
        public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
            if (assistant == null) {
                [...]
                assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
            }
            return assistant;
        }
    
        @Override
        public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
            return new IInformationControlCreator() {
                public IInformationControl createInformationControl(Shell parent) {
                    return new DefaultInformationControl(parent,new HTMLTextPresenter(false));
                }
            };
        }
    }
    

  • 然后,提案可以在方法 getAdditionalProposalInfo()
  • public class MyProposal implements ICompletionProposal {
        [...]
        @Override
        public String getAdditionalProposalInfo() {
            return "<b>Hello</b> <i>World</i>!";
        }
    }
    

    For the styled information box (just like in JDT).

    Styled additionnal information


  • The DefaultInformationControl instance need to received a HTMLTextPresenter.
  • import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
    
    public class MyConfiguration extends SourceViewerConfiguration {
    
    
        [...]
        public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
            if (assistant == null) {
                [...]
                assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
            }
            return assistant;
        }
    
        @Override
        public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
            return new IInformationControlCreator() {
                public IInformationControl createInformationControl(Shell parent) {
                    return new DefaultInformationControl(parent,new HTMLTextPresenter(false));
                }
            };
        }
    }
    
  • Proposals can then use basic HTML tags in the string from method getAdditionalProposalInfo().
  • public class MyProposal implements ICompletionProposal {
        [...]
        @Override
        public String getAdditionalProposalInfo() {
            return "<b>Hello</b> <i>World</i>!";
        }
    }
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文