@@ -59,6 +59,18 @@ public JSGraphQLAnnotationResult collectInformation(@NotNull PsiFile file, @NotN
5959 if (buffer .length () > 0 ) {
6060 final String environment = JSGraphQLLanguageInjectionUtil .getEnvironment (file );
6161 final AnnotationsResponse annotations = JSGraphQLNodeLanguageServiceClient .getAnnotations (buffer .toString (), file .getProject (), environment );
62+ if (annotations != null ) {
63+ for (Annotation annotation : annotations .getAnnotations ()) {
64+ LogicalPosition from = getLogicalPosition (annotation .getFrom ());
65+ int fromOffset = editor .logicalPositionToOffset (from );
66+ final PsiElement errorElement = getPsiElementAtErrorOffset (file , fromOffset );
67+ if (errorElement instanceof JSGraphQLErrorContextAware ) {
68+ final String message = StringUtils .substringBefore (annotation .getMessage (), "\n " );
69+ final JSGraphQLErrorContextAware errorContextAware = (JSGraphQLErrorContextAware ) errorElement ;
70+ annotation .setErrorInContext (errorContextAware .isErrorInContext (message ));
71+ }
72+ }
73+ }
6274 return new JSGraphQLAnnotationResult (annotations , editor );
6375 }
6476 } else if (file instanceof JSGraphQLSchemaFile ) {
@@ -108,19 +120,16 @@ public void visitElement(PsiElement element) {
108120 return ;
109121 }
110122 for (Annotation annotation : annotationsReponse .getAnnotations ()) {
123+ if (!annotation .isErrorInContext ()) {
124+ continue ;
125+ }
111126 LogicalPosition from = getLogicalPosition (annotation .getFrom ());
112127 LogicalPosition to = getLogicalPosition (annotation .getTo ());
113128 int fromOffset = editor .logicalPositionToOffset (from );
114129 int toOffset = editor .logicalPositionToOffset (to );
115130 HighlightSeverity severity = "error" .equals (annotation .getSeverity ()) ? HighlightSeverity .ERROR : HighlightSeverity .WARNING ;
116131 if (fromOffset < toOffset ) {
117132 final String message = StringUtils .substringBefore (annotation .getMessage (), "\n " );
118- final PsiElement errorElement = getPsiElementAtErrorOffset (file , fromOffset );
119- if (errorElement instanceof JSGraphQLErrorContextAware ) {
120- if (!((JSGraphQLErrorContextAware ) errorElement ).isErrorInContext (message )) {
121- continue ;
122- }
123- }
124133 holder .createAnnotation (severity , TextRange .create (fromOffset , toOffset ), message );
125134 errors .add (new JSGraphQLErrorResult (message , fileName , annotation .getSeverity (), from .line +1 , from .column +1 )); // +1 is for UI lines/columns
126135 }
0 commit comments