Skip to content

Commit 910c2aa

Browse files
authored
[IJ Plugin] Make Java and Kotlin dependencies optional (#6304)
1 parent 559cd05 commit 910c2aa

File tree

9 files changed

+31
-16
lines changed

9 files changed

+31
-16
lines changed

intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/lsp/LspUtil.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/normalizedcache/NormalizedCacheToolWindowFactory.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.apollographql.ijplugin.telemetry.TelemetryEvent.ApolloIjNormalizedCac
1414
import com.apollographql.ijplugin.telemetry.TelemetryEvent.ApolloIjNormalizedCacheOpenDeviceFile
1515
import com.apollographql.ijplugin.telemetry.TelemetryEvent.ApolloIjNormalizedCacheOpenLocalFile
1616
import com.apollographql.ijplugin.telemetry.telemetryService
17+
import com.apollographql.ijplugin.util.isAndroidPluginPresent
1718
import com.apollographql.ijplugin.util.logw
1819
import com.apollographql.ijplugin.util.showNotification
1920
import com.intellij.icons.AllIcons

intellij-plugin/src/main/kotlin/com/apollographql/ijplugin/normalizedcache/PullFromDevice.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ import java.io.File
1414
import java.nio.file.Paths
1515
import java.util.concurrent.TimeUnit
1616

17-
val isAndroidPluginPresent = try {
18-
Class.forName("com.android.ddmlib.AndroidDebugBridge")
19-
true
20-
} catch (e: ClassNotFoundException) {
21-
false
22-
}
23-
2417
fun getConnectedDevices(): List<IDevice> {
2518
return AndroidDebugBridge.createBridge(1, TimeUnit.SECONDS).devices.sortedBy { it.name }
2619
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import com.apollographql.ijplugin.gradle.GradleToolingModelService
55
import com.apollographql.ijplugin.graphql.GraphQLConfigService
66
import com.apollographql.ijplugin.lsp.ApolloLspAppService
77
import com.apollographql.ijplugin.lsp.ApolloLspProjectService
8-
import com.apollographql.ijplugin.lsp.isLspAvailable
98
import com.apollographql.ijplugin.settings.ProjectSettingsService
109
import com.apollographql.ijplugin.studio.fieldinsights.FieldInsightsService
1110
import com.apollographql.ijplugin.studio.sandbox.SandboxService
1211
import com.apollographql.ijplugin.telemetry.TelemetryService
12+
import com.apollographql.ijplugin.util.isLspAvailable
1313
import com.apollographql.ijplugin.util.logd
1414
import com.intellij.openapi.components.service
1515
import com.intellij.openapi.project.DumbService
@@ -32,7 +32,7 @@ internal class ApolloProjectManagerListener : ProjectManagerListener {
3232
project.service<SandboxService>()
3333
project.service<FieldInsightsService>()
3434
project.service<TelemetryService>()
35-
if (isLspAvailable()) {
35+
if (isLspAvailable) {
3636
project.service<ApolloLspProjectService>()
3737
application.service<ApolloLspAppService>()
3838
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.apollographql.ijplugin.settings
22

3+
import com.apollographql.ijplugin.util.isJavaPluginPresent
4+
import com.apollographql.ijplugin.util.isKotlinPluginPresent
5+
import com.apollographql.ijplugin.util.isLspAvailable
36
import com.intellij.openapi.components.PersistentStateComponent
47
import com.intellij.openapi.components.Service
58
import com.intellij.openapi.components.State
@@ -56,6 +59,14 @@ class AppSettingsService : PersistentStateComponent<AppSettingsStateImpl>, AppSe
5659
application.messageBus.syncPublisher(AppSettingsListener.TOPIC).settingsChanged(_state)
5760
}
5861
}
62+
63+
override fun initializeComponent() {
64+
// Running in an IDE without the Java or Kotlin plugin (e.g. RustRover): the user is most likely not an Apollo Kotlin developer.
65+
// In that case, the LSP mode (if available) is the best default.
66+
if (isLspAvailable && (!isJavaPluginPresent || !isKotlinPluginPresent)) {
67+
lspModeEnabled = true
68+
}
69+
}
5970
}
6071

6172
interface AppSettingsState {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.apollographql.ijplugin.util
2+
3+
val isLspAvailable = runCatching { Class.forName("com.intellij.platform.lsp.api.LspServerManager") }.isSuccess
4+
5+
val isAndroidPluginPresent = runCatching { Class.forName("com.android.ddmlib.AndroidDebugBridge") }.isSuccess
6+
7+
val isJavaPluginPresent = runCatching { Class.forName("com.intellij.psi.PsiJavaFile") }.isSuccess
8+
9+
val isKotlinPluginPresent = runCatching { Class.forName("org.jetbrains.kotlin.psi.KtFile") }.isSuccess
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<idea-plugin>
2+
<!-- Add here declarations that only work in presence of the Java plugin -->
3+
</idea-plugin>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<idea-plugin>
2+
<!-- Add here declarations that only work in presence of the Java plugin -->
3+
</idea-plugin>

intellij-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<!-- In most cases, this should be the same list as what is listed under gradle.properties/platformPlugins -->
99
<!-- See https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html#declaring-plugin-dependencies -->
1010
<depends>com.intellij.modules.platform</depends>
11-
<depends>com.intellij.modules.java</depends>
12-
<depends>org.jetbrains.kotlin</depends>
11+
<depends optional="true" config-file="com.apollographql.ijplugin-java.xml">com.intellij.modules.java</depends>
12+
<depends optional="true" config-file="com.apollographql.ijplugin-kotlin.xml">org.jetbrains.kotlin</depends>
1313
<depends>com.intellij.gradle</depends>
1414
<depends>com.intellij.lang.jsgraphql</depends>
1515
<depends>org.toml.lang</depends>

0 commit comments

Comments
 (0)