2013-02-04 13 views
0

我將以下代碼實現到MySemanticHighlightingCalculator中,並且一個元素的顏色按預期更改。但默認的默認突出顯示,例如關鍵字的紫色不再起作用。Xtext:語義突出顯示意外行爲

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; 
    } 

我知道默認高亮也不會之間的偏移和偏移來applyed +長度,但我希望它的文件的其餘部分。

回答

1

您的突出顯示配置必須擴展DefaultHighlightingConfiguration,您必須調用super.configure()。這將做到這一點。

請注意,resource.getParseResult()在某些罕見情況下可能爲空。

+0

thx,爲我工作:) – ph09