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

时间:2021-10-30 10:19:41

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.

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

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

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

2 个解决方案

#1


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.

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

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 ;)

容易,不是吗..如果你知道该怎么做;)

#2


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

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

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


  • The DefaultInformationControl instance need to received a HTMLTextPresenter.
  • 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));
                }
            };
        }
    }
    

  • Proposals can then use basic HTML tags in the string from method getAdditionalProposalInfo().
  • 然后,提案可以使用方法getAdditionalProposalInfo()中的字符串中的基本HTML标记。

    public class MyProposal implements ICompletionProposal {
        [...]
        @Override
        public String getAdditionalProposalInfo() {
            return "<b>Hello</b> <i>World</i>!";
        }
    }
    

    #1


    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.

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

    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 ;)

    容易,不是吗..如果你知道该怎么做;)

    #2


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

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

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


  • The DefaultInformationControl instance need to received a HTMLTextPresenter.
  • 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));
                }
            };
        }
    }
    

  • Proposals can then use basic HTML tags in the string from method getAdditionalProposalInfo().
  • 然后,提案可以使用方法getAdditionalProposalInfo()中的字符串中的基本HTML标记。

    public class MyProposal implements ICompletionProposal {
        [...]
        @Override
        public String getAdditionalProposalInfo() {
            return "<b>Hello</b> <i>World</i>!";
        }
    }