Change comment symbol in Xtext editor

718 Views Asked by At

I have an Xtext grammar and the generated editor elements. The parser knows that comments start with "--" but hitting Ctrl+7 does insert "//". Also, the green, italic highlighting of comments does only happen with "//" and not with "--". Where can I change this behaviour?

2

There are 2 best solutions below

2
On BEST ANSWER

if you do not want to override SL_COMMENT then you have to hook into the corresponding places

  • for the highlighting: DefaultAntlrTokenToAttributeIdMapper
  • for the toggle sl comment action: ISingleLineCommentHelper.getDefaultPrefixes(ISourceViewer, String)
3
On

have you overridden the SL_COMMENT rule?

If you want to insert "--" instead of "//", "--" should be the first alternative in SL_COMMENT rule:

terminal SL_COMMENT:
    ('--'|'//') !('\n'|'\r')* ('\r'? '\n')?
;