88package com .intellij .lang .jsgraphql .ide .editor ;
99
1010import com .google .gson .Gson ;
11- import com .intellij .codeHighlighting .Pass ;
1211import com .intellij .codeInsight .daemon .LineMarkerInfo ;
1312import com .intellij .codeInsight .daemon .LineMarkerProvider ;
1413import com .intellij .icons .AllIcons ;
2928import com .intellij .openapi .util .Ref ;
3029import com .intellij .openapi .util .text .StringUtil ;
3130import com .intellij .openapi .vfs .VirtualFile ;
32- import com .intellij .psi .PsiDirectory ;
3331import com .intellij .psi .PsiElement ;
3432import com .intellij .psi .PsiErrorElement ;
3533import com .intellij .psi .PsiFile ;
3937
4038import java .net .MalformedURLException ;
4139import java .net .URL ;
42- import java .util .Collection ;
43- import java .util .List ;
4440import java .util .Map ;
4541import java .util .Optional ;
4642import java .util .stream .Stream ;
4945 * Line marker for running an introspection against a configured endpoint url in a .graphqlconfig file
5046 */
5147public 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}
0 commit comments