我正在尝试通过最近的Eclipse最新版本提供的通用编辑器模板来实现IContentAssistProcessor
接口以扩展eclipse插件。我无法按照自己的意愿运行自动完成功能。到目前为止,当我运行目标Eclipse平台并在文本中执行自动完成时(对于我来说,是在字母后按CTRL + Space
),我打开一个菜单,然后自动完成我的文本,到目前为止效果很好但是下一次我打开此菜单时,列表将丢失之前选择的最后一项。如何更改此程序以始终保持展开的物品的完整列表?代码是:
public class DbdContentAssistProcessor implements IContentAssistProcessor {
public static final String[] PROPOSALS = new String[] {
"ield(NAME,",
"ield(DESC,",
"ield(ASG,",
"ield(SCAN,",
"ield(PHAS,",
"ield(PINI,",
"ield(SDIS," };
public static final String[] PROPOSALS1 = new String[] {
"ecord(ai, ",
"ecord(bi, ",
"ecord(calcout, ",
"ecord(longin, ",
"ecord(longout, ",
"ecord(string in, ",
"ecord(string out, ",
"ecord(lsi, ",
"ecord(lso, ",
"ecord(waveform, ",
"ecord(bi, ",
"ecord(bo, ",
};
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
String text = viewer.getDocument().get();
String natureTag= "f";
String projectReferenceTag="r";
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (text.length() >= natureTag.length() && text.substring(offset - natureTag.length(), offset).equals(natureTag)) {
IProjectNatureDescriptor[] natureDescriptors= workspace.getNatureDescriptors();
ICompletionProposal[] proposals = new ICompletionProposal[natureDescriptors.length];
for (int i= 0; i < natureDescriptors.length; i++) {
IProjectNatureDescriptor descriptor= natureDescriptors[i];
proposals[i] = new CompletionProposal(descriptor.getNatureId(), offset, 0, descriptor.getNatureId().length());
}
return Arrays.asList(PROPOSALS).stream().filter(proposal -> !viewer.getDocument().get().contains(proposal))
.map(proposal -> new CompletionProposal(proposal, offset, 0, proposal.length()))
.toArray(ICompletionProposal[]::new);
}
if (text.length() >= projectReferenceTag.length() && text.substring(offset - projectReferenceTag.length(), offset).equals(projectReferenceTag)) {
IProjectNatureDescriptor[] natureDescriptors= workspace.getNatureDescriptors();
ICompletionProposal[] proposals1 = new ICompletionProposal[natureDescriptors.length];
for (int i= 0; i < natureDescriptors.length; i++) {
IProjectNatureDescriptor descriptor1= natureDescriptors[i];
proposals1[i] = new CompletionProposal(descriptor1.getNatureId(), offset, 0, descriptor1.getNatureId().length());
}
return Arrays.asList(PROPOSALS1).stream().filter(proposal -> !viewer.getDocument().get().contains(proposal))
.map(proposal1 -> new CompletionProposal(proposal1, offset, 0, proposal1.length()))
.toArray(ICompletionProposal[]::new);
}
return new ICompletionProposal[0];
}
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}
@Override
public char[] getCompletionProposalAutoActivationCharacters() {
return new char[] { '¨' };
@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}
@Override
public String getErrorMessage() {
return null;
}
@Override
public IContextInformationValidator getContextInformationValidator() {
return null;
}
}