Token mapped with PsiBuilder.remapCurrentToken still highlighted as original token

Hi,
I have an issue with a lexer/parser and PsiBuilder.remapCurrentToken.

The lexer returns a token, e.g. FOR_KEYWORD . The parser changes this to WORD using PsiBuilder.remapCurrentToken . PsiViewer displays that the psi tree contains the token "WORD" as leaf element, which is fine IMHO.

The highlighter has a configuration for the FOR_KEYWORD and another one for WORD. The token WORD (i.e. the remapped token) is still highlighted using the colors of the FOR_KEYWORD and not as WORD token.

Is there any way to fix this?

Changing the lexer is not possible, because the language (Bash) interprets keywords (e.g. for) as normal string literals depending on the context (e.g. echo for).

Thanks a lot for any hints!
Wallaby

2 comments

The problem is that lexer highlighting pass works on a VirtualFile (file text) level.
This happens before any parsing takes place if ever.
(For example for large files no parsing is performed at all.)

A separate highlighting lexer is created and run through raw text to determine the required token highlighting.
The results are stored and never updated for performance reasons.

An approach I took in SQL Support where lots of keywords are optional and shouldn't be rendered as such is
to add an Annotator which uses

com.intellij.openapi.editor.markup.TextAttributes#ERASE_MARKER

attribute and then forces a different text attributes on a non-keyword identifier:


        annotationHolder.createInfoAnnotation(element, null).setEnforcedTextAttributes(TextAttributes.ERASE_MARKER);
        annotationHolder.createInfoAnnotation(element, null).setEnforcedTextAttributes(
          EditorColorsManager.getInstance().getGlobalScheme().getAttributes(HighlighterColors.TEXT));



API References:
com.intellij.openapi.editor.ex.util.LexerEditorHighlighter and
com.intellij.openapi.fileTypes.SyntaxHighlighterProvider
com.intellij.lang.annotation.Annotator
0

Hi,
thanks for your reply! This is working perfectly...

Best regards,
Wallaby

0

Please sign in to leave a comment.