2

私はEclipse用の独自のPowerShellエディタープラグインを作成しています。現在、エディターには優れたコード強調表示があります。しかし、優れたアウトラインビューとフォーマットを作成できるようにするには、優れたドキュメントパーティションが必要です。そこで、現在2つのルールだけでパーティションスキャナー(RuleBasedPartitionScannerを拡張)を作成しました。

IToken psComment = new Token(PS_COMMENT);
IToken psFunction = new Token(PS_FUNCTION);

IPredicateRule[] rules = new IPredicateRule[2];

rules[0] = new EndOfLineRule("#", psComment);
rules[1] = new SingleLineRule("function", "{", psFunction);

setPredicateRules(rules);

FastPartitionerを使用して、必要なすべてのコンテンツタイプ(IDocument.DEFAULT_CONTENT_TYPE、PowershellPartitionScanner.PS_FUNCTION、PowershellPartitionScanner.PS_COMMENT)を使用してドキュメントで作成しました。

強調表示のために、スキャナーを作成しました(RuleBasedScannerを拡張します)。

構成クラスで、getPresentrationReconcilerをオーバーライドしました。

DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
                new PowershellScanner());
reconciler.setDamager(dr, PowershellPartitionScanner.PS_FUNCTION);
reconciler.setRepairer(dr, PowershellPartitionScanner.PS_FUNCTION);
dr = new DefaultDamagerRepairer(new PowershellScanner());
reconciler.setDamager(dr, PowershellPartitionScanner.PS_COMMENT);
reconciler.setRepairer(dr, PowershellPartitionScanner.PS_COMMENT);
dr = new DefaultDamagerRepairer(new PowershellScanner());
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
return reconciler;

私は上書きしました:

@Override
    public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
        return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
                PowershellPartitionScanner.PS_COMMENT,
                PowershellPartitionScanner.PS_FUNCTION };
    }

現在、ドキュメントは適切にパーティション化されています。ただし、コードの強調表示はありません。すべてが黒です。

ドキュメントを分割していない場合、強調表示は機能します。

私は何かが足りないのですか?

ありがとう

4

2 に答える 2

3

間違いは、強調したいものに重複するルールを定義することにあると思います。PowershellPartitionScannerで定義されているルールがPowershellScannerでも定義されているようです。

これらのパーティションルールを強調表示するためにPowershellScannerを使用するのではなく、その目的のために別のスキャナーを使用してください。

1.まず、PowershellPartitionScannerですでに定義されている重複するルールをPowershellScannerから削除します。

2.次に、パーティションを強調表示するためのスキャナーを定義します(たとえば、Eclipseサンプル「SampleJavaEditor」から)

class SingleTokenScanner extends BufferedRuleBasedScanner {
    public SingleTokenScanner(TextAttribute attribute) {
        setDefaultReturnToken(new Token(attribute));
    }
}

3.構成クラス内でgetPresentrationReconcilerを変更します。

DefaultDamagerRepairer dr;

// General highlighting
dr = new DefaultDamagerRepairer(new PowershellScanner());
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

// Function partition
dr = new DefaultDamagerRepairer(
    new SingleTokenScanner(
        new TextAttribute(colorManager.getColor(new RGB(255, 0, 0)))
    )
);
reconciler.setDamager(dr, PowershellPartitionScanner.PS_FUNCTION);
reconciler.setRepairer(dr, PowershellPartitionScanner.PS_FUNCTION);

// Comment partition
dr = new DefaultDamagerRepairer(
    new SingleTokenScanner(
        new TextAttribute(colorManager.getColor(new RGB(0, 255, 0)))
    )
);
reconciler.setDamager(dr, PowershellPartitionScanner.PS_COMMENT);
reconciler.setRepairer(dr, PowershellPartitionScanner.PS_COMMENT);

return reconciler;
于 2012-12-12T01:35:40.607 に答える
0

実際、これで私の問題は解決しました。私のFileDocumentProvider拡張機能にIDocumentExtension3が追加されました。それを使用することにより、私は両方のタイプのルールを持つことができました。

IDocument document = super.createDocument(element);
IDocumentExtension3 docExtension = (IDocumentExtension3) document;
if (document != null) {
    IDocumentPartitioner partitioner = new DebugPartitioner(Activator
            .getDefault().getPowershellPartitionScanner(),
            new String[] { IDocument.DEFAULT_CONTENT_TYPE,
                    PowershellPartitionScanner.PS_FUNCTION,
                    PowershellPartitionScanner.PS_COMMENT });
    partitioner.connect(document);
    docExtension.setDocumentPartitioner(
            Activator.POWERSHELL_PARTITIONING, partitioner);
}
return document;

解決策はPyDeveclipseプラグインで見つかりました。

于 2012-12-12T09:39:54.090 に答える