Skip to content

Commit

Permalink
[IJ Plugin] Play nice with IDEs without Kotlin/Gradle (#6358)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BoD authored Jan 20, 2025
1 parent d6e1222 commit 7e8570f
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.apollographql.ijplugin.settings.ProjectSettingsService
import com.apollographql.ijplugin.studio.fieldinsights.FieldInsightsService
import com.apollographql.ijplugin.studio.sandbox.SandboxService
import com.apollographql.ijplugin.telemetry.TelemetryService
import com.apollographql.ijplugin.util.isGradlePluginPresent
import com.apollographql.ijplugin.util.isKotlinPluginPresent
import com.apollographql.ijplugin.util.isLspAvailable
import com.apollographql.ijplugin.util.logd
import com.intellij.openapi.components.service
Expand All @@ -23,15 +25,18 @@ internal class ApolloProjectManagerListener : ProjectManagerListener {

// Initialize all services on project open.
// But wait for 'smart mode' to do it.
// Most of these services can't operate without the Kotlin and Gradle plugins (e.g. in RustRover).
DumbService.getInstance(project).runWhenSmart {
logd("apolloVersion=" + project.apolloProjectService.apolloVersion)
project.service<ApolloCodegenService>()
project.service<GraphQLConfigService>()
project.service<GradleToolingModelService>()
project.service<ProjectSettingsService>()
project.service<SandboxService>()
project.service<FieldInsightsService>()
project.service<TelemetryService>()
if (isKotlinPluginPresent && isGradlePluginPresent) {
project.service<ApolloCodegenService>()
project.service<GraphQLConfigService>()
project.service<GradleToolingModelService>()
project.service<ProjectSettingsService>()
project.service<SandboxService>()
project.service<FieldInsightsService>()
project.service<TelemetryService>()
}
if (isLspAvailable) {
project.service<ApolloLspProjectService>()
application.service<ApolloLspAppService>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.apollographql.ijplugin.settings
import com.apollographql.ijplugin.ApolloBundle
import com.apollographql.ijplugin.project.apolloProjectService
import com.apollographql.ijplugin.settings.studio.ApiKeyDialog
import com.apollographql.ijplugin.util.isGradlePluginPresent
import com.apollographql.ijplugin.util.isKotlinPluginPresent
import com.intellij.openapi.observable.properties.PropertyGraph
import com.intellij.openapi.project.Project
import com.intellij.ui.AddEditRemovePanel
Expand Down Expand Up @@ -32,21 +34,22 @@ class SettingsComponent(private val project: Project) {
private var addEditRemovePanel: AddEditRemovePanel<ApolloKotlinServiceConfiguration>? = null

val panel: JPanel = panel {
// Some options are irrelevant without the Kotlin or Gradle plugins (e.g. in RustRover).
group(ApolloBundle.message("settings.codegen.title")) {
row {
chkAutomaticCodegenTriggering = checkBox(ApolloBundle.message("settings.codegen.automaticCodegenTriggering.text"))
.comment(ApolloBundle.message("settings.codegen.automaticCodegenTriggering.comment"))
.bindSelected(automaticCodegenTriggeringProperty)
.component
}
}
}.visible(isKotlinPluginPresent && isGradlePluginPresent)
group(ApolloBundle.message("settings.graphqlPlugin.title")) {
row {
checkBox(ApolloBundle.message("settings.graphqlPlugin.contributeConfigurationToGraphqlPlugin.text"))
.comment(ApolloBundle.message("settings.graphqlPlugin.contributeConfigurationToGraphqlPlugin.comment"))
.bindSelected(contributeConfigurationToGraphqlPluginProperty)
}
}
}.visible(isKotlinPluginPresent && isGradlePluginPresent)
group(ApolloBundle.message("settings.studio.title")) {
if (!project.apolloProjectService.apolloVersion.isAtLeastV4) {
row { label(ApolloBundle.message("settings.studio.apiKeys.needV4.message")) }
Expand Down Expand Up @@ -98,7 +101,7 @@ class SettingsComponent(private val project: Project) {
.comment(ApolloBundle.message("settings.studio.apiKeys.comment"))
}
}
}
}.visible(isKotlinPluginPresent && isGradlePluginPresent)

group(ApolloBundle.message("settings.telemetry.telemetryEnabled.title")) {
row {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ val isAndroidPluginPresent = runCatching { Class.forName("com.android.ddmlib.And
val isJavaPluginPresent = runCatching { Class.forName("com.intellij.psi.PsiJavaFile") }.isSuccess

val isKotlinPluginPresent = runCatching { Class.forName("org.jetbrains.kotlin.psi.KtFile") }.isSuccess

val isGradlePluginPresent = runCatching { Class.forName("org.jetbrains.plugins.gradle.util.GradleConstants") }.isSuccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<idea-plugin>
<!-- Add here declarations that only work in presence of the Gradle plugin -->

<extensions defaultExtensionNs="com.intellij">
<!-- Listen to Gradle sync -->
<externalSystemTaskNotificationListener implementation="com.apollographql.ijplugin.gradle.GradleListener" />

</extensions>
</idea-plugin>
Loading

0 comments on commit 7e8570f

Please sign in to comment.