【问题标题】:Xtext: semantic highlighting unexpected behaviourXtext:语义突出显示意外行为
【发布时间】:2013-01-19 13:08:51
【问题描述】:

我在 MySemanticHighlightingCalculator 中实现了以下代码,并且一个元素的颜色按预期更改。但是默认的默认突出显示,例如关键字的紫色不再起作用。

INode root = resource.getParseResult().getRootNode();
        BidiTreeIterator<INode> iterator = root.getAsTreeIterable().iterator();
        while (iterator.hasNext()) {
            INode node = iterator.next();
            if (node.getSemanticElement() instanceof ParameterDesc) {
                ParameterDesc paramdesc = (ParameterDesc) node
                        .getSemanticElement();
                if (paramdesc.isUnselected() == true) {
                    acceptor.addPosition(
                            node.getOffset(),
                            node.getLength(),
                            MySemanticHighlightingConfiguration.PARAMETER_DESCRIPTION);
                }
            }
        }

public static final String PARAMETER_DESCRIPTION = "Parameter_Description";

public void configure(IHighlightingConfigurationAcceptor acceptor) {
    addType(acceptor, PARAMETER_DESCRIPTION, 255, 0, 0, TextAttribute.STRIKETHROUGH);
}

public void addType(IHighlightingConfigurationAcceptor acceptor, String s,
        int r, int g, int b, int style) {
    TextStyle textStyle = new TextStyle();
    textStyle.setColor(new RGB(r, g, b));
    textStyle.setStyle(style);
    acceptor.acceptDefaultHighlighting(s, s, textStyle);
}

但是当我从 MyDSLUiModule 中删除 MySemanticHighlightingConfiguration 时,默认突出显示再次起作用:

public Class<? extends IHighlightingConfiguration> bindIHighlightingConfiguration() {
        return MySemanticHighlightingConfiguration.class;
    }

我知道默认突出显示不会在偏移量和偏移量+长度之间应用,但我希望它用于文档的其余部分。

【问题讨论】:

    标签: syntax-highlighting default semantics xtext


    【解决方案1】:

    您的突出显示配置必须扩展DefaultHighlightingConfiguration,并且您必须调用super.configure()。这样就可以了。

    请注意,resource.getParseResult() 在极少数情况下可能为空。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      • 2015-01-01
      • 2011-10-26
      • 2021-07-30
      • 2016-08-17
      • 1970-01-01
      相关资源
      最近更新 更多