How to implement content assist's documentation popup in Eclipse RCP

一曲冷凌霜 提交于 2019-12-21 05:38:14

问题


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)


回答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.

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


  • 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>!";
        }
    }
    


    来源:https://stackoverflow.com/questions/887248/how-to-implement-content-assists-documentation-popup-in-eclipse-rcp

    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!