0

エディターにコンテンツ アシストを追加しようとしています。私は追加しました

    public IContentAssistant getContentAssistant(ISourceViewer sv) {
    ContentAssistant ca = new ContentAssistant();
    IContentAssistProcessor pr = new TagCompletionProcessor();
    ca.setContentAssistProcessor(pr, XMLPartitionScanner.XML_TAG);
    ca.setContentAssistProcessor(pr, IDocument.DEFAULT_CONTENT_TYPE);
    return ca;
}

エディターの構成に移動し、完了プロセッサ クラスを作成します。

public class TagCompletionProcessor implements IContentAssistProcessor {
private ITypedRegion wordRegion;
private String currentWord;
private SmartTreeSet tags;
public TagCompletionProcessor() {
    tags = new SmartTreeSet();
    //filling tags skipped
}
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer,
        int offset) {
    System.out.println("compute");
    wordRegion = viewer.getDocument().getDocumentPartitioner().getPartition(offset);
    try {
        int offs = wordRegion.getOffset();
        int len = wordRegion.getLength();
        currentWord = viewer.getDocument().get(offs, len);
        return tags.getProposals(currentWord.toLowerCase(), offs, len);
    } catch (BadLocationException e) {
        return null;
    }
}
@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 IContextInformationValidator getContextInformationValidator() {
    return null;
}
@Override
public String getErrorMessage() {
    return "No tags found";
}

}

...しかし、それは機能していません。初期化は正常に行われますが、自動アクティベーションは機能せず、ctrl-space を押すと (Bindings ext ポイントに org.eclipse.ui.edit.text.contentAssist.proposals コマンドを追加しました) 空のリストが表示されます (これもカーソルの近くではなく、一定の場所にあります)。私は何を間違っていますか?

4

3 に答える 3

0

ドキュメントがIDocumentExtension3を実装している場合は、アシスタントのパーティションを設定する必要があります..

ca.setDocumentPartitioning(MyPartitionScanner.MyPartitioning);

この助けを願っています

于 2009-05-20T10:29:09.660 に答える
0

アクションをエディターに登録し、デフォルトのものに置き換える必要があります。これは、コンテンツ アシスト アクションでそれを行う方法の例です。

http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_actions.htm

于 2009-08-09T17:48:01.460 に答える
0

申し訳ありませんが、途中でいくつかの null 出力がありました。なんという失敗=(

于 2011-01-19T09:48:18.650 に答える