Annotator implementation pass question.


I have the following problem:

Given a language in which the following are valid statements:

key = "value$VARa";

The statements are parsed in the following tree;



I need the following:

Highlight the QuotedValue in a certain format and the Var in another format.

I have implemented the Annotator with the following code:

if ( psiElement is QuotedValue ) { annotateAsQuoted(); }
else if ( psiElement is Var ) { annotateAsVar(); }

but it doesn't work ( the Var annotation is missing ).

I logged teh calls of the Annotator an saw that the calls into it are done bottom up (first the leafs then the parents all the way to the PsiFile element) and i thought that the QuotedValue annotation is somehow overriding the Var annotation. Then i did a small hack: after annotating the QuotedValue i descended the tree until i found the Var element and annotated that one again. This didn't work also.

Any ideas ?

Sincerely,
ToMiC

6 comments

You need syntax highlighter for just coloring, annotator is intended for
detection of semantic problems. Check out Java Script plugin sources for
particular implementation details.

Toader Mihai Claudiu wrote:

I have the following problem:

Given a language in which the following are valid statements:

key = "value$VARa";

The statements are parsed in the following tree;

Declaration[ > Key[ > Identifier("key") > ], > QuotedValue[ > Value[ > Var("$ROOT") > ]("value$ROOTa") > ]("\"value$VARa\"") > ]("key = \"value$VARa\";") > ]]>

I need the following:

Highlight the QuotedValue in a certain format and the Var in another format.

I have implemented the Annotator with the following code:

if ( psiElement is QuotedValue ) { annotateAsQuoted(); }
else if ( psiElement is Var ) { annotateAsVar(); }

but it doesn't work ( the Var annotation is missing ).

I logged teh calls of the Annotator an saw that the calls into it are done bottom up (first the leafs then the parents all the way to the PsiFile element) and i thought that the QuotedValue annotation is somehow overriding the Var annotation. Then i did a small hack: after annotating the QuotedValue i descended the tree until i found the Var element and annotated that one again. This didn't work also.

Any ideas ?

Sincerely,
ToMiC



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0


I also use the SyntaxHighlighter but the problem is that i want semantically signifiant coloring. Also i can't detect the color by looking at the lexer tokens alone. For example:

key = value;

the key and value are the same token type as detected by the lexer (Identifier). If I make the Identifier to have a certain TextAttributte then i will not be able to make the proper distinctions. The same with this example:

"value" -> QuotedValue[Value[Identifier]]
value -> Value[Identifier]

And i want to be able to distinguish between a QuotedValue and a Value (by a different background or something);

Is this kind of stuff possible using only the Highlighter ?

Also .. the Annotations created by the annotator can or can't be nested ?

Sincerely,
ToMiC


0

Given that annotator detects problems it does not visit children nodes
that have problems.
For simple cases you can use lexer states to generate different token
types in highlighting mode.
For complex cases (e.g. separate highlighting for static/instance vars)
you'd need custom code.

Toader Mihai Claudiu wrote:

I also use the SyntaxHighlighter but the problem is that i want semantically signifiant coloring. Also i can't detect the color by looking at the lexer tokens alone. For example:

key = value;

the key and value are the same token type as detected by the lexer (Identifier). If I make the Identifier to have a certain TextAttributte then i will not be able to make the proper distinctions. The same with this example:

"value" -> QuotedValue[Value[Identifier]]
value -> Value[Identifier]

And i want to be able to distinguish between a QuotedValue and a Value (by a different background or something);

Is this kind of stuff possible using only the Highlighter ?

Also .. the Annotations created by the annotator can or can't be nested ?

Sincerely,
ToMiC




--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

I can force it to visit the childrens when i know that this is the case. Like this:



The problem is that it doesn't take them into consideration. Maybe this is by design.

I can try to rework the lexing to use states but it might not be enough or getting way too complicated. If that would be the case what custom code should i try to use (going to the Annotator way or i need more classes in the OpenApi) ?

Sincerely,
ToMiC

0

Toader, I think this "feature" makes language plugin development
unnecessarily difficult as well. You should vote for
http://jetbrains.net/jira/browse/IDEABKL-3420 and
http://jetbrains.net/jira/browse/IDEA-5520

Toader Mihai Claudiu wrote:

I can force it to visit the childrens when i know that this is the case. Like this:

if (psiElement instanceof QuotedValue) { > Annotation annotation = holder.createInfoAnnotation(psiElement, null); > annotation.setTextAttributes(CfgHighlighter.STRING); > > if (psiElement instanceof QuotedValue) { > LOG.info("Descending "); > QuotedValue quotedValue = (QuotedValue) psiElement; > Value value = quotedValue.getValue(); > if ( value != null ) { > for (PsiElement childPsiElement : value.getChildren()) { > LOG.info("child: " + childPsiElement); > if (childPsiElement instanceof Macro) { > annotate(childPsiElement, holder); > } > } > } > LOG.info("Done descending"); > } > } > ]]>

The problem is that it doesn't take them into consideration. Maybe this is by design.

I can try to rework the lexing to use states but it might not be enough or getting way too complicated. If that would be the case what custom code should i try to use (going to the Annotator way or i need more classes in the OpenApi) ?

Sincerely,
ToMiC

0


Hello Keith,

I hacked the lexer in the end :) but it was ugly i hade to make like 6-7
states where i had only one state before.

Something more usefull would have been a way to put TextAttributtes on PSI
elements the same way you do it with the lexer tokens
and with the possibility to override that inside the child PSI elements.

A mechanism similar to the way CSS stylesheets work for html but not that
complicated: just merge the child TextAttributtes settings with the parent
TextAttributtes settings.

Sincerely,
ToMiC

Toader, I think this "feature" makes language plugin development
unnecessarily difficult as well. You should vote for
http://jetbrains.net/jira/browse/IDEABKL-3420 and
http://jetbrains.net/jira/browse/IDEA-5520

Toader Mihai Claudiu wrote:

>> I can force it to visit the childrens when i know that this is the
>> case. Like this:
>>
>> > if (psiElement instanceof QuotedValue) { >> Annotation annotation = holder.createInfoAnnotation(psiElement, >> null); >> annotation.setTextAttributes(CfgHighlighter.STRING); >> if (psiElement instanceof QuotedValue) { >> LOG.info("Descending "); >> QuotedValue quotedValue = (QuotedValue) psiElement; >> Value value = quotedValue.getValue(); >> if ( value != null ) { >> for (PsiElement childPsiElement : value.getChildren()) { >> LOG.info("child: " + childPsiElement); >> if (childPsiElement instanceof Macro) { >> annotate(childPsiElement, holder); >> } >> } >> } >> LOG.info("Done descending"); >> } >> } >> ]]>
>> The problem is that it doesn't take them into consideration. Maybe
>> this is by design.
>>
>> I can try to rework the lexing to use states but it might not be
>> enough or getting way too complicated. If that would be the case what
>> custom code should i try to use (going to the Annotator way or i need
>> more classes in the OpenApi) ?
>>
>> Sincerely,
>> ToMiC


0

Please sign in to leave a comment.