How to implement content support help popup in Eclipse RCP

I implemented my own editor and added code completion functionality to it. My content assistant is registered in the view source configuration as follows:

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 click Ctrl+ SPACEinside the desired section, a shutdown popup window appears and works as expected.

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

+3
source share
2 answers

Well,

I will answer the question myself; -)

assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));

. CompletionProposals () , ProposalInfo , , .

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

.

, .. , ;)

+3

( JDT).

Styled additionnal information


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

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

Source: https://habr.com/ru/post/1708724/


All Articles