Skip to content

Commit bd7409e

Browse files
committed
Resolve fragment references under progress in annotator to ensure WebStorm 2017.3 compatibility (#115)
1 parent 7cc0aee commit bd7409e

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/main/com/intellij/lang/jsgraphql/ide/annotator/JSGraphQLAnnotator.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/main/com/intellij/lang/jsgraphql/languageservice/api/Annotation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class Annotation {
1515
private Pos from;
1616
private Pos to;
1717

18+
private boolean errorInContext = true;
19+
1820
public String getMessage() {
1921
return message;
2022
}
@@ -34,4 +36,12 @@ public Pos getFrom() {
3436
public Pos getTo() {
3537
return to;
3638
}
39+
40+
public boolean isErrorInContext() {
41+
return errorInContext;
42+
}
43+
44+
public void setErrorInContext(boolean errorInContext) {
45+
this.errorInContext = errorInContext;
46+
}
3747
}

0 commit comments

Comments
 (0)