Skip to content

Commit 7e8570f

Browse files
authored
[IJ Plugin] Play nice with IDEs without Kotlin/Gradle (#6358)
* Fix missing Kotlin classes when running inspections in IDEs without the Kotlin plugin * Mark the Gradle plugin as optional, and move all components specific to Apollo Kotlin to the Kotlin plugin dependency file. * Remove duplicate action
1 parent d6e1222 commit 7e8570f

File tree

8 files changed

+378
-281
lines changed

8 files changed

+378
-281
lines changed

intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/project/ApolloProjectManagerListener.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import com.apollographql.ijplugin.settings.ProjectSettingsService
99
import com.apollographql.ijplugin.studio.fieldinsights.FieldInsightsService
1010
import com.apollographql.ijplugin.studio.sandbox.SandboxService
1111
import com.apollographql.ijplugin.telemetry.TelemetryService
12+
import com.apollographql.ijplugin.util.isGradlePluginPresent
13+
import com.apollographql.ijplugin.util.isKotlinPluginPresent
1214
import com.apollographql.ijplugin.util.isLspAvailable
1315
import com.apollographql.ijplugin.util.logd
1416
import com.intellij.openapi.components.service
@@ -23,15 +25,18 @@ internal class ApolloProjectManagerListener : ProjectManagerListener {
2325

2426
// Initialize all services on project open.
2527
// But wait for 'smart mode' to do it.
28+
// Most of these services can't operate without the Kotlin and Gradle plugins (e.g. in RustRover).
2629
DumbService.getInstance(project).runWhenSmart {
2730
logd("apolloVersion=" + project.apolloProjectService.apolloVersion)
28-
project.service<ApolloCodegenService>()
29-
project.service<GraphQLConfigService>()
30-
project.service<GradleToolingModelService>()
31-
project.service<ProjectSettingsService>()
32-
project.service<SandboxService>()
33-
project.service<FieldInsightsService>()
34-
project.service<TelemetryService>()
31+
if (isKotlinPluginPresent && isGradlePluginPresent) {
32+
project.service<ApolloCodegenService>()
33+
project.service<GraphQLConfigService>()
34+
project.service<GradleToolingModelService>()
35+
project.service<ProjectSettingsService>()
36+
project.service<SandboxService>()
37+
project.service<FieldInsightsService>()
38+
project.service<TelemetryService>()
39+
}
3540
if (isLspAvailable) {
3641
project.service<ApolloLspProjectService>()
3742
application.service<ApolloLspAppService>()

intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/settings/SettingsComponent.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.apollographql.ijplugin.settings
33
import com.apollographql.ijplugin.ApolloBundle
44
import com.apollographql.ijplugin.project.apolloProjectService
55
import com.apollographql.ijplugin.settings.studio.ApiKeyDialog
6+
import com.apollographql.ijplugin.util.isGradlePluginPresent
7+
import com.apollographql.ijplugin.util.isKotlinPluginPresent
68
import com.intellij.openapi.observable.properties.PropertyGraph
79
import com.intellij.openapi.project.Project
810
import com.intellij.ui.AddEditRemovePanel
@@ -32,21 +34,22 @@ class SettingsComponent(private val project: Project) {
3234
private var addEditRemovePanel: AddEditRemovePanel<ApolloKotlinServiceConfiguration>? = null
3335

3436
val panel: JPanel = panel {
37+
// Some options are irrelevant without the Kotlin or Gradle plugins (e.g. in RustRover).
3538
group(ApolloBundle.message("settings.codegen.title")) {
3639
row {
3740
chkAutomaticCodegenTriggering = checkBox(ApolloBundle.message("settings.codegen.automaticCodegenTriggering.text"))
3841
.comment(ApolloBundle.message("settings.codegen.automaticCodegenTriggering.comment"))
3942
.bindSelected(automaticCodegenTriggeringProperty)
4043
.component
4144
}
42-
}
45+
}.visible(isKotlinPluginPresent && isGradlePluginPresent)
4346
group(ApolloBundle.message("settings.graphqlPlugin.title")) {
4447
row {
4548
checkBox(ApolloBundle.message("settings.graphqlPlugin.contributeConfigurationToGraphqlPlugin.text"))
4649
.comment(ApolloBundle.message("settings.graphqlPlugin.contributeConfigurationToGraphqlPlugin.comment"))
4750
.bindSelected(contributeConfigurationToGraphqlPluginProperty)
4851
}
49-
}
52+
}.visible(isKotlinPluginPresent && isGradlePluginPresent)
5053
group(ApolloBundle.message("settings.studio.title")) {
5154
if (!project.apolloProjectService.apolloVersion.isAtLeastV4) {
5255
row { label(ApolloBundle.message("settings.studio.apiKeys.needV4.message")) }
@@ -98,7 +101,7 @@ class SettingsComponent(private val project: Project) {
98101
.comment(ApolloBundle.message("settings.studio.apiKeys.comment"))
99102
}
100103
}
101-
}
104+
}.visible(isKotlinPluginPresent && isGradlePluginPresent)
102105

103106
group(ApolloBundle.message("settings.telemetry.telemetryEnabled.title")) {
104107
row {

intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/util/Environment.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ val isAndroidPluginPresent = runCatching { Class.forName("com.android.ddmlib.And
77
val isJavaPluginPresent = runCatching { Class.forName("com.intellij.psi.PsiJavaFile") }.isSuccess
88

99
val isKotlinPluginPresent = runCatching { Class.forName("org.jetbrains.kotlin.psi.KtFile") }.isSuccess
10+
11+
val isGradlePluginPresent = runCatching { Class.forName("org.jetbrains.plugins.gradle.util.GradleConstants") }.isSuccess
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<idea-plugin>
2+
<!-- Add here declarations that only work in presence of the Gradle plugin -->
3+
4+
<extensions defaultExtensionNs="com.intellij">
5+
<!-- Listen to Gradle sync -->
6+
<externalSystemTaskNotificationListener implementation="com.apollographql.ijplugin.gradle.GradleListener" />
7+
8+
</extensions>
9+
</idea-plugin>

0 commit comments

Comments
 (0)