Skip to content

Commit c350e73

Browse files
committed
Fix LineMarkerInfo deprecated usages
1 parent 63b99a9 commit c350e73

File tree

3 files changed

+50
-52
lines changed

3 files changed

+50
-52
lines changed

resources/messages/GraphQLMessages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ graphql.notification.dont.show.again.message=Don't show again
2424
graphql.notification.trust.all.hosts=Trust all hosts
2525
graphql.notification.file.out.of.scope=The .graphqlconfig associated with this file does not include it. Schema discovery and language tooling will use entire project.
2626
graphql.notification.file.out.of.scope.edit=Edit .graphqlconfig globs
27+
graphql.notification.configuration.error=GraphQL configuration error
2728

2829
# Introspection
2930
graphql.introspection.missing.data=Expected `data` key to be present in query result.
3031
graphql.introspection.missing.schema=Expected `__schema` key to be present in query result data.
3132
graphql.introspection.errors=Introspection query returned errors: {0}
33+
graphql.introspection.run.query=Run introspection query to generate GraphQL SDL schema file
3234

3335
# Progress
3436
graphql.progress.executing.introspection.query=Executing GraphQL introspection query

src/main/com/intellij/lang/jsgraphql/ide/editor/GraphQLIntrospectEndpointUrlLineMarkerProvider.java

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package com.intellij.lang.jsgraphql.ide.editor;
99

1010
import com.google.gson.Gson;
11-
import com.intellij.codeHighlighting.Pass;
1211
import com.intellij.codeInsight.daemon.LineMarkerInfo;
1312
import com.intellij.codeInsight.daemon.LineMarkerProvider;
1413
import com.intellij.icons.AllIcons;
@@ -29,7 +28,6 @@
2928
import com.intellij.openapi.util.Ref;
3029
import com.intellij.openapi.util.text.StringUtil;
3130
import com.intellij.openapi.vfs.VirtualFile;
32-
import com.intellij.psi.PsiDirectory;
3331
import com.intellij.psi.PsiElement;
3432
import com.intellij.psi.PsiErrorElement;
3533
import com.intellij.psi.PsiFile;
@@ -39,8 +37,6 @@
3937

4038
import java.net.MalformedURLException;
4139
import java.net.URL;
42-
import java.util.Collection;
43-
import java.util.List;
4440
import java.util.Map;
4541
import java.util.Optional;
4642
import java.util.stream.Stream;
@@ -49,8 +45,6 @@
4945
* Line marker for running an introspection against a configured endpoint url in a .graphqlconfig file
5046
*/
5147
public class GraphQLIntrospectEndpointUrlLineMarkerProvider implements LineMarkerProvider {
52-
private String pathOfConfigFileParent;
53-
5448
@Nullable
5549
@Override
5650
public LineMarkerInfo<?> getLineMarkerInfo(@NotNull PsiElement element) {
@@ -61,31 +55,41 @@ public LineMarkerInfo<?> getLineMarkerInfo(@NotNull PsiElement element) {
6155
final JsonProperty jsonProperty = (JsonProperty) element;
6256
final Ref<String> urlRef = Ref.create();
6357
if (isEndpointUrl(jsonProperty, urlRef) && !hasErrors(jsonProperty.getContainingFile())) {
64-
return new LineMarkerInfo<>(jsonProperty, jsonProperty.getTextRange(), AllIcons.RunConfigurations.TestState.Run, Pass.UPDATE_ALL, o -> "Run introspection query to generate GraphQL SDL schema file", (evt, jsonUrl) -> {
65-
66-
String introspectionUrl;
67-
if (jsonUrl.getValue() instanceof JsonStringLiteral) {
68-
introspectionUrl = ((JsonStringLiteral) jsonUrl.getValue()).getValue();
69-
} else {
70-
return;
71-
}
72-
73-
final GraphQLConfigVariableAwareEndpoint endpoint = getEndpoint(introspectionUrl, jsonProperty, element.getContainingFile().getVirtualFile());
74-
if (endpoint == null) {
75-
return;
76-
}
77-
78-
String schemaPath = getSchemaPath(jsonProperty, true);
79-
if (StringUtil.isEmptyOrSpaces(schemaPath)) {
80-
return;
81-
}
82-
83-
final Project project = element.getProject();
84-
final VirtualFile introspectionSourceFile = element.getContainingFile().getVirtualFile();
85-
86-
GraphQLIntrospectionService.getInstance(project).performIntrospectionQueryAndUpdateSchemaPathFile(endpoint, schemaPath, introspectionSourceFile);
87-
88-
}, GutterIconRenderer.Alignment.CENTER);
58+
PsiElement anchor = jsonProperty.getNameElement().getFirstChild();
59+
if (anchor == null) return null;
60+
61+
return new LineMarkerInfo<>(
62+
anchor,
63+
anchor.getTextRange(),
64+
AllIcons.RunConfigurations.TestState.Run,
65+
o -> GraphQLBundle.message("graphql.introspection.run.query"),
66+
(evt, el) -> {
67+
String introspectionUrl;
68+
if (jsonProperty.getValue() instanceof JsonStringLiteral) {
69+
introspectionUrl = ((JsonStringLiteral) jsonProperty.getValue()).getValue();
70+
} else {
71+
return;
72+
}
73+
74+
final GraphQLConfigVariableAwareEndpoint endpoint = getEndpoint(introspectionUrl, jsonProperty, element.getContainingFile().getVirtualFile());
75+
if (endpoint == null) {
76+
return;
77+
}
78+
79+
String schemaPath = getSchemaPath(jsonProperty, true);
80+
if (StringUtil.isEmptyOrSpaces(schemaPath)) {
81+
return;
82+
}
83+
84+
final Project project = element.getProject();
85+
final VirtualFile introspectionSourceFile = element.getContainingFile().getVirtualFile();
86+
87+
GraphQLIntrospectionService.getInstance(project).performIntrospectionQueryAndUpdateSchemaPathFile(endpoint, schemaPath, introspectionSourceFile);
88+
89+
},
90+
GutterIconRenderer.Alignment.CENTER,
91+
() -> GraphQLBundle.message("graphql.introspection.run.query")
92+
);
8993
}
9094
}
9195
return null;
@@ -188,14 +192,13 @@ private GraphQLConfigVariableAwareEndpoint getEndpoint(String url, JsonProperty
188192
return new GraphQLConfigVariableAwareEndpoint(endpointConfig, urlJsonProperty.getProject(), configFile);
189193

190194
} catch (Exception e) {
191-
Notifications.Bus.notify(new Notification("GraphQL", "GraphQL Configuration Error", e.getMessage(), NotificationType.ERROR), urlJsonProperty.getProject());
195+
Notifications.Bus.notify(new Notification(
196+
GraphQLNotificationUtil.NOTIFICATION_GROUP_ID,
197+
GraphQLBundle.message("graphql.notification.configuration.error"),
198+
e.getMessage(),
199+
NotificationType.ERROR
200+
), urlJsonProperty.getProject());
192201
}
193202
return null;
194203
}
195-
196-
@Override
197-
public void collectSlowLineMarkers(@NotNull List<? extends PsiElement> elements,
198-
@NotNull Collection<? super LineMarkerInfo<?>> result) {
199-
// compatibility with 182
200-
}
201204
}

src/main/com/intellij/lang/jsgraphql/ide/editor/GraphQLIntrospectionJsonToSDLLineMarkerProvider.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
package com.intellij.lang.jsgraphql.ide.editor;
99

10-
import com.intellij.codeHighlighting.Pass;
1110
import com.intellij.codeInsight.daemon.LineMarkerInfo;
1211
import com.intellij.codeInsight.daemon.LineMarkerProvider;
1312
import com.intellij.icons.AllIcons;
@@ -29,9 +28,6 @@
2928
import org.jetbrains.annotations.NotNull;
3029
import org.jetbrains.annotations.Nullable;
3130

32-
import java.util.Collection;
33-
import java.util.List;
34-
3531
/**
3632
* Line marker which shows an action to turn a GraphQL Introspection JSON result into a GraphQL schema expressed in GraphQL SDL.
3733
*/
@@ -88,23 +84,20 @@ public LineMarkerInfo<?> getLineMarkerInfo(@NotNull PsiElement element) {
8884
}
8985
});
9086

87+
PsiElement anchor = jsonProperty.getNameElement().getFirstChild();
88+
if (anchor == null) return null;
89+
9190
return new LineMarkerInfo<>(
92-
jsonProperty,
93-
jsonProperty.getTextRange(),
91+
anchor,
92+
anchor.getTextRange(),
9493
AllIcons.RunConfigurations.TestState.Run,
95-
Pass.UPDATE_ALL,
9694
o -> GraphQLBundle.message("graphql.line.marker.generate.schema.file"),
9795
(evt, elt) -> generateAction.get().run(),
98-
GutterIconRenderer.Alignment.CENTER
96+
GutterIconRenderer.Alignment.CENTER,
97+
() -> GraphQLBundle.message("graphql.line.marker.generate.schema.file")
9998
);
10099
}
101100
}
102101
return null;
103102
}
104-
105-
@Override
106-
public void collectSlowLineMarkers(@NotNull List<? extends PsiElement> elements,
107-
@NotNull Collection<? super LineMarkerInfo<?>> result) {
108-
// compatibility with 182
109-
}
110103
}

0 commit comments

Comments
 (0)