77 */
88package com .intellij .lang .jsgraphql .endpoint .doc .ide .annotator ;
99
10- import java .util .HashMap ;
11- import java .util .Map ;
12-
13- import org .jetbrains .annotations .NotNull ;
14-
1510import com .intellij .lang .annotation .Annotation ;
1611import com .intellij .lang .annotation .AnnotationHolder ;
1712import com .intellij .lang .annotation .Annotator ;
2217import com .intellij .lang .jsgraphql .endpoint .psi .JSGraphQLEndpointInputValueDefinition ;
2318import com .intellij .lang .jsgraphql .endpoint .psi .JSGraphQLEndpointInputValueDefinitions ;
2419import com .intellij .openapi .editor .DefaultLanguageHighlighterColors ;
20+ import com .intellij .openapi .editor .colors .CodeInsightColors ;
2521import com .intellij .openapi .editor .colors .TextAttributesKey ;
22+ import com .intellij .openapi .util .Key ;
2623import com .intellij .psi .PsiComment ;
2724import com .intellij .psi .PsiElement ;
2825import com .intellij .psi .tree .IElementType ;
2926import com .intellij .psi .util .PsiTreeUtil ;
27+ import org .jetbrains .annotations .NotNull ;
28+
29+ import java .util .HashMap ;
30+ import java .util .Map ;
3031
3132/**
3233 * Highlights GraphQL Endpoint documentation comments
@@ -41,13 +42,35 @@ public class JSGraphQLEndpointDocHighlightAnnotator implements Annotator {
4142 ATTRIBUTES .put (JSGraphQLEndpointDocTokenTypes .DOCVALUE , DefaultLanguageHighlighterColors .DOC_COMMENT_TAG_VALUE );
4243 }
4344
45+ private static final Key <PsiElement > TODO_ELEMENT = Key .create ("JSGraphQLEndpointDocHighlightAnnotator.Todo" );
4446
4547 @ SuppressWarnings ("unchecked" )
4648 @ Override
4749 public void annotate (@ NotNull PsiElement element , @ NotNull AnnotationHolder holder ) {
50+
51+ final IElementType elementType = element .getNode ().getElementType ();
52+
53+ // highlight TO-DO items
54+ if (elementType == JSGraphQLEndpointDocTokenTypes .DOCTEXT ) {
55+ final String elementText = element .getText ().toLowerCase ();
56+ if (isTodoToken (elementText )) {
57+ setTextAttributes (element , holder , CodeInsightColors .TODO_DEFAULT_ATTRIBUTES );
58+ holder .getCurrentAnnotationSession ().putUserData (TODO_ELEMENT , element );
59+ return ;
60+ } else {
61+ PsiElement prevSibling = element .getPrevSibling ();
62+ while (prevSibling != null ) {
63+ if (prevSibling == holder .getCurrentAnnotationSession ().getUserData (TODO_ELEMENT )) {
64+ setTextAttributes (element , holder , CodeInsightColors .TODO_DEFAULT_ATTRIBUTES );
65+ return ;
66+ }
67+ prevSibling = prevSibling .getPrevSibling ();
68+ }
69+ }
70+ }
71+
4872 final PsiComment comment = PsiTreeUtil .getContextOfType (element , PsiComment .class );
4973 if (comment != null && JSGraphQLEndpointDocPsiUtil .isDocumentationComment (comment )) {
50- final IElementType elementType = element .getNode ().getElementType ();
5174 final TextAttributesKey textAttributesKey = ATTRIBUTES .get (elementType );
5275 if (textAttributesKey != null ) {
5376 setTextAttributes (element , holder , textAttributesKey );
@@ -85,6 +108,13 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
85108 }
86109 }
87110
111+ private boolean isTodoToken (String elementText ) {
112+ if (elementText .startsWith ("todo" )) {
113+ return elementText .length () == 4 || !Character .isAlphabetic (elementText .charAt (4 ));
114+ }
115+ return false ;
116+ }
117+
88118 private void setTextAttributes (PsiElement element , AnnotationHolder holder , TextAttributesKey key ) {
89119 final Annotation annotation = holder .createInfoAnnotation (element , null );
90120 annotation .setTextAttributes (key );
0 commit comments