Skip to content

Commit 85f5116

Browse files
committed
Build working on 2020.3
1 parent afd5406 commit 85f5116

File tree

13 files changed

+165
-33
lines changed

13 files changed

+165
-33
lines changed

build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ tasks {
7676
}
7777
}
7878

79+
compileTestKotlin {
80+
kotlinOptions {
81+
jvmTarget = properties("javaVersion")
82+
}
83+
}
84+
7985
runIde {
8086
autoReloadPlugins.set(true)
8187
}

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ pluginVersion=0.0.2-alpha.5
44

55
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
66
# for insight into build numbers and IntelliJ Platform versions.
7+
# TODO 2020.3 is supported with GraphQL 3.0.0-2020.3 (203.5981.155)
78
pluginSinceBuild=211.0
89
pluginUntilBuild=213.*
910

1011
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
1112
# See https://jb.gg/intellij-platform-builds-list for available build versions.
12-
pluginVerifierIdeVersions=2021.1.3, 2021.3.1
13+
pluginVerifierIdeVersions=2020.3.1, 2021.1.1, 2021.3.1
1314

1415
platformType=IU
1516
platformVersion=IU-213-EAP-SNAPSHOT
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package nl.jrdie.idea.springql;
2+
3+
import org.jetbrains.annotations.Nullable;
4+
5+
@FunctionalInterface
6+
public interface GraphQLSchemaEventListener {
7+
void onGraphQLSchemaChanged(@Nullable Integer schemaVersion);
8+
}

src/main/java/nl/jrdie/idea/springql/svc/QLIdeService.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,4 @@ default boolean isApolloFederationNode(Node<?> node, boolean checkSupport) {
5757

5858
@NotNull
5959
QLSchemaRegistry getSchemaRegistry();
60-
61-
// @NotNull
62-
// Project getApplicableProject();
63-
6460
}

src/main/java/nl/jrdie/idea/springql/svc/QLIdeServiceImpl.java

Lines changed: 97 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package nl.jrdie.idea.springql.svc;
22

33
import com.intellij.lang.java.JavaLanguage;
4-
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaChangeTracker;
54
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaInfo;
65
import com.intellij.lang.jsgraphql.schema.GraphQLSchemaProvider;
7-
import com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryTypes;
86
import com.intellij.lang.jsgraphql.types.language.FieldDefinition;
97
import com.intellij.lang.jsgraphql.types.language.InputValueDefinition;
108
import com.intellij.lang.jsgraphql.types.language.Node;
@@ -26,22 +24,16 @@
2624
import com.intellij.psi.stubs.StubIndex;
2725
import com.intellij.psi.stubs.StubIndexKey;
2826
import com.intellij.psi.util.PsiModificationTracker;
29-
import java.text.NumberFormat;
30-
import java.time.Duration;
31-
import java.util.Collections;
32-
import java.util.List;
33-
import java.util.Locale;
34-
import java.util.Objects;
35-
import java.util.Set;
36-
import java.util.concurrent.atomic.AtomicLong;
37-
import java.util.concurrent.atomic.AtomicReference;
38-
import java.util.stream.Collectors;
27+
import com.intellij.util.messages.Topic;
28+
import nl.jrdie.idea.springql.GraphQLSchemaEventListener;
3929
import nl.jrdie.idea.springql.index.MutableQLIdeIndex;
4030
import nl.jrdie.idea.springql.index.QLIdeIndex;
4131
import nl.jrdie.idea.springql.index.entry.QLClassSchemaMappingIndexEntry;
4232
import nl.jrdie.idea.springql.index.entry.QLMethodSchemaMappingIndexEntry;
4333
import nl.jrdie.idea.springql.index.processor.QLAnnotationIndexProcessor;
4434
import nl.jrdie.idea.springql.types.SchemaMappingSummary;
35+
import nl.jrdie.idea.springql.utils.JSGraphQLPlugin;
36+
import nl.jrdie.idea.springql.utils.JSGraphQLVersionBypassUtils;
4537
import nl.jrdie.idea.springql.utils.QLIdeUtil;
4638
import nl.jrdie.idea.springql.utils.UExtKt;
4739
import org.jetbrains.annotations.NotNull;
@@ -55,6 +47,17 @@
5547
import org.jetbrains.uast.UMethod;
5648
import org.jetbrains.uast.UastContextKt;
5749

50+
import java.text.NumberFormat;
51+
import java.time.Duration;
52+
import java.util.Collections;
53+
import java.util.List;
54+
import java.util.Locale;
55+
import java.util.Objects;
56+
import java.util.Set;
57+
import java.util.concurrent.atomic.AtomicLong;
58+
import java.util.concurrent.atomic.AtomicReference;
59+
import java.util.stream.Collectors;
60+
5861
public class QLIdeServiceImpl implements QLIdeService, Disposable {
5962

6063
private static final Logger LOGGER = Logger.getInstance(QLIdeServiceImpl.class);
@@ -83,7 +86,7 @@ public class QLIdeServiceImpl implements QLIdeService, Disposable {
8386

8487
@NotNull private final Project project;
8588

86-
@Nullable private QLSchemaRegistry cachedSchemaRegistry;
89+
// TODO @Nullable private QLSchemaRegistry cachedSchemaRegistry;
8790

8891
@Nullable private QLIdeIndex cachedIdeIndex;
8992

@@ -98,6 +101,50 @@ public QLIdeServiceImpl(Project project) {
98101
this.javaModificationCount = new AtomicLong(0);
99102
this.kotlinModificationCount = new AtomicLong(0);
100103
this.graphQLModificationCount = new AtomicLong(0);
104+
105+
tryRegisterGraphQLSchemaChangeListener();
106+
}
107+
108+
@SuppressWarnings({"unchecked", "JavaReflectionMemberAccess"})
109+
private void tryRegisterGraphQLSchemaChangeListener() {
110+
// Only implement this for the 2020.3 compatible JS GraphQL version (3.0.0-2020.3)
111+
if (!JSGraphQLPlugin.INSTANCE.is2020dot3version()) {
112+
return;
113+
}
114+
115+
// ----------------------------------------
116+
// I DISGUST EVERYTHING ABOUT THIS FUNCTION
117+
// ----------------------------------------
118+
119+
// https://github.com/jimkyndemeyer/js-graphql-intellij-plugin/blob/3.0.0/src/main/com/intellij/lang/jsgraphql/schema/GraphQLSchemaChangeListener.java
120+
// com.intellij.lang.jsgraphql.schema
121+
try {
122+
Class<?> graphQLSchemaChangeListenerCls =
123+
Class.forName("com.intellij.lang.jsgraphql.schema.GraphQLSchemaChangeListener");
124+
Topic<? super GraphQLSchemaEventListener> targetTopic =
125+
(Topic<? super GraphQLSchemaEventListener>)
126+
graphQLSchemaChangeListenerCls.getField("TOPIC").get(null);
127+
128+
if (targetTopic == null) {
129+
throw new IllegalStateException("TOPIC Not found"); // TODO Error message
130+
}
131+
132+
// Automatically disposed when `this` service is disposed (we implement Disposable)
133+
project
134+
.getMessageBus()
135+
.connect(this)
136+
.subscribe(
137+
targetTopic,
138+
(GraphQLSchemaEventListener)
139+
schemaVersion -> {
140+
// Force reloading of the index when a schema file changes
141+
QLIdeServiceImpl.this.getIndex(true);
142+
});
143+
} catch (Exception e) {
144+
throw new IllegalStateException(
145+
"Failed to register schema change listener for 2020.3 JS GraphQL plugin version @ GraphQL Spring Support",
146+
e);
147+
}
101148
}
102149

103150
@NotNull
@@ -311,7 +358,8 @@ private boolean hasFieldWithNameAndType(
311358

312359
@Override
313360
public boolean isApolloFederationSupportEnabled() {
314-
return GraphQLLibraryTypes.FEDERATION.isEnabled(this.project);
361+
return !JSGraphQLPlugin.INSTANCE.is2020dot3version()
362+
&& JSGraphQLVersionBypassUtils.isApolloFederationEnabled(this.project);
315363
}
316364

317365
@Nullable
@@ -469,10 +517,8 @@ public List<UAnnotation> findNearestSchemaMappingAnnotations(UElement uElement)
469517
@NotNull
470518
@Override
471519
public QLSchemaRegistry getSchemaRegistry() {
520+
// TODO Cache registry?
472521
return new QLSchemaRegistry(getTypeDefinitionRegistry(), getGraphQLSchemaInfo());
473-
// return Objects.requireNonNullElseGet(cachedSchemaRegistry,
474-
// () -> cachedSchemaRegistry = new
475-
// QLSchemaRegistry(getTypeDefinitionRegistry()));
476522
}
477523

478524
@NotNull
@@ -523,14 +569,40 @@ private boolean updateAndCheckModified() {
523569
boolean kotlinModified =
524570
this.kotlinModificationCount.getAndSet(kotlinModificationCount) != kotlinModificationCount;
525571

526-
long graphQLModificationCount =
527-
GraphQLSchemaChangeTracker.getInstance(this.project)
528-
.getSchemaModificationTracker()
529-
.getModificationCount();
530-
531-
boolean graphQLModified =
532-
this.graphQLModificationCount.getAndSet(graphQLModificationCount)
533-
!= graphQLModificationCount;
572+
boolean graphQLModified = false;
573+
574+
// TODO Fix this 2020.3 support logic
575+
if (!JSGraphQLPlugin.INSTANCE.is2020dot3version()) {
576+
//noinspection CommentedOutCode
577+
try {
578+
Class<?> changeTracker =
579+
Class.forName("com.intellij.lang.jsgraphql.schema.GraphQLSchemaChangeTracker");
580+
Object schemaTracker =
581+
changeTracker.getMethod("getInstance", Project.class).invoke(null, this.project);
582+
Object modificationTracker =
583+
schemaTracker
584+
.getClass()
585+
.getMethod("getSchemaModificationTracker")
586+
.invoke(schemaTracker);
587+
long graphQLModificationCount =
588+
(long)
589+
schemaTracker
590+
.getClass()
591+
.getMethod("getModificationCount")
592+
.invoke(modificationTracker);
593+
594+
// long graphQLModificationCount =
595+
// GraphQLSchemaChangeTracker.getInstance(this.project)
596+
// .getSchemaModificationTracker()
597+
// .getModificationCount();
598+
599+
graphQLModified =
600+
this.graphQLModificationCount.getAndSet(graphQLModificationCount)
601+
!= graphQLModificationCount;
602+
} catch (Exception e) {
603+
throw new RuntimeException(e);
604+
}
605+
}
534606

535607
return javaModified || kotlinModified || graphQLModified;
536608
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package nl.jrdie.idea.springql.utils;
2+
3+
import com.intellij.openapi.project.Project;
4+
import java.lang.reflect.Field;
5+
import java.lang.reflect.Method;
6+
7+
/**
8+
* Psi Project error :,(
9+
*
10+
* @see JSGraphQLPlugin
11+
*/
12+
public class JSGraphQLVersionBypassUtils {
13+
14+
private JSGraphQLVersionBypassUtils() {}
15+
16+
public static boolean isApolloFederationEnabled(Project project) {
17+
try {
18+
Class<?> libTypes =
19+
Class.forName("com.intellij.lang.jsgraphql.schema.library.GraphQLLibraryTypes");
20+
Field federation = libTypes.getDeclaredField("FEDERATION");
21+
Object federationStatic = federation.get(null);
22+
Method isEnabled = federationStatic.getClass().getMethod("isEnabled", Project.class);
23+
return (boolean) isEnabled.invoke(federationStatic, project);
24+
} catch (Exception e) {
25+
return false;
26+
}
27+
// return GraphQLLibraryTypes.FEDERATION.isEnabled(project);
28+
}
29+
}

src/main/kotlin/nl/jrdie/idea/springql/QLBundle.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.PropertyKey
77
@NonNls
88
private const val BUNDLE = "messages.SpringGraphQLBundle"
99

10+
@Suppress("unused")
1011
object QLBundle : DynamicBundle(BUNDLE) {
1112

1213
@Suppress("SpreadOperator")

src/main/kotlin/nl/jrdie/idea/springql/icons/QLIcons.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package nl.jrdie.idea.springql.icons
33
import com.intellij.openapi.util.IconLoader
44
import javax.swing.Icon
55

6+
@Suppress("unused")
67
object QLIcons {
78

89
private fun getIcon(path: String): Icon {

src/main/kotlin/nl/jrdie/idea/springql/ide/completion/QLSchemaArgumentNameRefProvider.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.jetbrains.uast.UMethod
1111
import org.jetbrains.uast.expressions.UInjectionHost
1212
import org.jetbrains.uast.getUastParentOfType
1313

14+
@Suppress("FoldInitializerAndIfToElvis")
1415
class QLSchemaArgumentNameRefProvider : UastReferenceProvider(UInjectionHost::class.java) {
1516

1617
override fun getReferencesByElement(element: UElement, context: ProcessingContext): Array<PsiReference> {

src/main/kotlin/nl/jrdie/idea/springql/ide/gutter/marker/SchemaMappingToSchemaLineMarkerProvider.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import nl.jrdie.idea.springql.svc.QLIdeService
1111
import org.jetbrains.uast.UMethod
1212
import org.jetbrains.uast.toUElementOfType
1313

14+
@Suppress("FoldInitializerAndIfToElvis")
1415
class SchemaMappingToSchemaLineMarkerProvider : RelatedItemLineMarkerProvider() {
1516

1617
override fun collectNavigationMarkers(

0 commit comments

Comments
 (0)