pyr*_*ade 6 intellij-idea bnf jflex intellij-plugin grammar-kit
我正在尝试使用Grammar-Kit插件为IntelliJ开发自定义语言插件.我很容易为定义的标记提供语法高亮,但我无法弄清楚如何在元素或标记 - 父级别突出显示.
这是一个快速而又脏的示例语言 - https://github.com/carymrobbins/intellij-plugin-example
解
正如@ignatov建议的那样,扩展Annotator类并在你的注册表中注册它plugin.xml
.在下面的示例中,我们command
通过定义visitCommand
方法来突出显示元素.
public class SimpleAnnotator implements Annotator {
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder holder) {
element.accept(new SimpleVisitor() {
@Override
public void visitCommand(@NotNull SimpleCommand o) {
super.visitCommand(o);
setHighlighting(o, holder, SimpleSyntaxHighlighter.COMMAND);
}
});
}
private static void setHighlighting(@NotNull PsiElement element, @NotNull AnnotationHolder holder,
@NotNull TextAttributesKey key) {
holder.createInfoAnnotation(element, null).setEnforcedTextAttributes(TextAttributes.ERASE_MARKER);
holder.createInfoAnnotation(element, null).setEnforcedTextAttributes(
EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key));
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1382 次 |
最近记录: |