I'm extending eclipse jdt's content assist,
and I wrote a class that implements IJavaCompletionProposalComputer,
and my code is like the following:
final static String[] fgProposals = { "A", "B" };
final static String[] fgInfo = { "<font color='red'>A_info</font>", "B_info" };
@Override
public List<ICompletionProposal>
computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
ICompletionProposal[] result = new ICompletionProposal[fgProposals.length];
for (int i= 0; i < fgProposals.length; i++) {
IContextInformation info = new ContextInformation("AA", "BB");
result[i]= new CompletionProposal(
fgProposals[i], context.getInvocationOffset(), 0,
fgProposals[i].length(), null, fgProposals[i],
info, fgInfo[i]);
}
return Arrays.asList(result);
}
However,
the additional info (the window at the right of the selected proposal)
ignores html tags and just shows plain text.
My question is the same as this topic:
HTML Formatting in Editor ContentAssit
I've read this,
but I can't understand the explanation they said.
Could anyone tell me how to solve this question with a clearer explanation?
A simple code snippet will help a lot!!
Thanks.
A simple code snippet is not possible because this is not simple!
Instead of your code returning an array of CompletionProposal
you must return an array of classes that implement both ICompletionProposal
and ICompletionProposalExtension3
.
One of the extra methods in ICompletionProposalExtension3
is
public IInformationControlCreator getInformationControlCreator()
This must return an IInformationControlCreator
class. This class just has one method:
public IInformationControl createInformationControl(Shell parent)
The returned IInformationControl
is the class that displays the proposals and can deal with HTML. There is a abstract class AbstractInformationControl
which implements some of the basic requirements but it is down to you to deal with the HTML.
One way to deal with the HTML is to use the SWT Browser
widget. There is a BrowserInformationControl
which does this but it is in the internal package org.eclipse.jface.internal.text.html
so it is not available for use by plugins.