Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IJ Plugin] Move Rover settings to own section and add note about needing v0.27.0+ #6278

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package com.apollographql.ijplugin.lsp
import com.apollographql.ijplugin.file.ApolloGraphQLFileType
import com.apollographql.ijplugin.icons.ApolloIcons
import com.apollographql.ijplugin.rover.RoverHelper
import com.apollographql.ijplugin.settings.SettingsConfigurable
import com.apollographql.ijplugin.settings.appSettingsState
import com.apollographql.ijplugin.settings.lsp.LspSettingsConfigurable
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
Expand All @@ -29,7 +29,7 @@ internal class ApolloLspServerSupportProvider : LspServerSupportProvider {
lspServer = lspServer,
currentFile = currentFile,
icon = ApolloIcons.StatusBar.Apollo,
settingsPageClass = SettingsConfigurable::class.java,
settingsPageClass = LspSettingsConfigurable::class.java,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.apollographql.ijplugin.settings

import com.apollographql.ijplugin.ApolloBundle
import com.apollographql.ijplugin.lsp.isLspAvailable
import com.apollographql.ijplugin.project.apolloProjectService
import com.apollographql.ijplugin.settings.lsp.lspGroup
import com.apollographql.ijplugin.settings.studio.ApiKeyDialog
import com.intellij.openapi.observable.properties.GraphProperty
import com.intellij.openapi.observable.properties.PropertyGraph
import com.intellij.openapi.project.Project
import com.intellij.ui.AddEditRemovePanel
Expand All @@ -16,13 +13,11 @@ import javax.swing.JCheckBox
import javax.swing.JComponent
import javax.swing.JPanel


class SettingsComponent(private val project: Project) {
private val propertyGraph = PropertyGraph()
private val automaticCodegenTriggeringProperty = propertyGraph.property(false)
private val contributeConfigurationToGraphqlPluginProperty = propertyGraph.property(false)
private val telemetryEnabledProperty = propertyGraph.property(false)
private val lspModeEnabledProperty: GraphProperty<Boolean> = propertyGraph.property(false)

var automaticCodegenTriggering: Boolean by automaticCodegenTriggeringProperty
var contributeConfigurationToGraphqlPlugin: Boolean by contributeConfigurationToGraphqlPluginProperty
Expand All @@ -32,7 +27,6 @@ class SettingsComponent(private val project: Project) {
addEditRemovePanel?.data = value.toMutableList()
}
var telemetryEnabled: Boolean by telemetryEnabledProperty
var lspModeEnabled: Boolean by lspModeEnabledProperty

private lateinit var chkAutomaticCodegenTriggering: JCheckBox
private var addEditRemovePanel: AddEditRemovePanel<ApolloKotlinServiceConfiguration>? = null
Expand Down Expand Up @@ -106,10 +100,6 @@ class SettingsComponent(private val project: Project) {
}
}

if (isLspAvailable()) {
lspGroup(lspModeEnabledProperty)
}

group(ApolloBundle.message("settings.telemetry.telemetryEnabled.title")) {
row {
checkBox(ApolloBundle.message("settings.telemetry.telemetryEnabled.text"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,21 @@ class SettingsConfigurable(private val project: Project) : Configurable {
return settingsComponent!!.automaticCodegenTriggering != project.projectSettingsState.automaticCodegenTriggering ||
settingsComponent!!.contributeConfigurationToGraphqlPlugin != project.projectSettingsState.contributeConfigurationToGraphqlPlugin ||
settingsComponent!!.apolloKotlinServiceConfigurations != project.projectSettingsState.apolloKotlinServiceConfigurations ||
settingsComponent!!.telemetryEnabled != appSettingsState.telemetryEnabled ||
settingsComponent!!.lspModeEnabled != appSettingsState.lspModeEnabled
settingsComponent!!.telemetryEnabled != appSettingsState.telemetryEnabled
}

override fun apply() {
project.projectSettingsState.automaticCodegenTriggering = settingsComponent!!.automaticCodegenTriggering
project.projectSettingsState.contributeConfigurationToGraphqlPlugin = settingsComponent!!.contributeConfigurationToGraphqlPlugin
project.projectSettingsState.apolloKotlinServiceConfigurations = settingsComponent!!.apolloKotlinServiceConfigurations
appSettingsState.telemetryEnabled = settingsComponent!!.telemetryEnabled
appSettingsState.lspModeEnabled = settingsComponent!!.lspModeEnabled
}

override fun reset() {
settingsComponent!!.automaticCodegenTriggering = project.projectSettingsState.automaticCodegenTriggering
settingsComponent!!.contributeConfigurationToGraphqlPlugin = project.projectSettingsState.contributeConfigurationToGraphqlPlugin
settingsComponent!!.apolloKotlinServiceConfigurations = project.projectSettingsState.apolloKotlinServiceConfigurations
settingsComponent!!.telemetryEnabled = appSettingsState.telemetryEnabled
settingsComponent!!.lspModeEnabled = appSettingsState.lspModeEnabled
}

override fun getPreferredFocusedComponent() = settingsComponent!!.preferredFocusedComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,45 @@ package com.apollographql.ijplugin.settings.lsp

import com.apollographql.ijplugin.ApolloBundle
import com.apollographql.ijplugin.rover.RoverHelper
import com.intellij.icons.AllIcons
import com.apollographql.ijplugin.settings.ApolloKotlinServiceConfiguration
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.observable.properties.GraphProperty
import com.intellij.ui.components.JBLabel
import com.intellij.openapi.observable.properties.PropertyGraph
import com.intellij.openapi.project.Project
import com.intellij.ui.AddEditRemovePanel
import com.intellij.ui.dsl.builder.AlignX
import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.Panel
import com.intellij.ui.dsl.builder.Row
import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.scale.JBUIScale
import com.intellij.ui.dsl.builder.panel
import javax.swing.JCheckBox
import javax.swing.JLabel
import javax.swing.SwingConstants
import javax.swing.JPanel

fun Panel.lspGroup(lspModeEnabledProperty: GraphProperty<Boolean>) {
var roverVersionLabel: Cell<JLabel>? = null
var installationInstructionsLink: Row? = null
group(JBLabel(ApolloBundle.message("settings.rover.title")).apply {
setHorizontalTextPosition(SwingConstants.LEFT)
setIconTextGap(JBUIScale.scale(8))
setIcon(AllIcons.General.Beta)
}) {
class LspSettingsComponent(private val project: Project) {
private val propertyGraph = PropertyGraph()
private val lspModeEnabledProperty: GraphProperty<Boolean> = propertyGraph.property(false)

var lspModeEnabled: Boolean by lspModeEnabledProperty

private lateinit var chkAutomaticCodegenTriggering: JCheckBox
private var addEditRemovePanel: AddEditRemovePanel<ApolloKotlinServiceConfiguration>? = null

val panel: JPanel = panel {
var roverVersionLabel: Cell<JLabel>? = null
var installationInstructionsLink: Row? = null
row {
text(ApolloBundle.message("settings.rover.intro"))
}

row {
roverVersionLabel = label(ApolloBundle.message("settings.rover.checking"))
.align(AlignX.FILL)
}

installationInstructionsLink =
row {
text(ApolloBundle.message("settings.rover.notInstalled.instructions"))
}
.visible(false)

buttonsGroup {
row {
radioButton(ApolloBundle.message("settings.rover.lsp.disabled"), null)
Expand All @@ -55,22 +58,23 @@ fun Panel.lspGroup(lspModeEnabledProperty: GraphProperty<Boolean>) {
.bindSelected(lspModeEnabledProperty)
}
}
}
ApplicationManager.getApplication().executeOnPooledThread {
val roverStatus = RoverHelper.getRoverStatus()
when (roverStatus) {
is RoverHelper.RoverStatus.Installed -> {
if (!roverStatus.hasLsp) {
roverVersionLabel!!.component.text = ApolloBundle.message("settings.rover.installed.noLsp", roverStatus.version)
installationInstructionsLink!!.visible(true)
} else {
roverVersionLabel!!.component.text = ApolloBundle.message("settings.rover.installed.withLsp", roverStatus.version)

ApplicationManager.getApplication().executeOnPooledThread {
val roverStatus = RoverHelper.getRoverStatus()
when (roverStatus) {
is RoverHelper.RoverStatus.Installed -> {
if (!roverStatus.hasLsp) {
roverVersionLabel!!.component.text = ApolloBundle.message("settings.rover.installed.noLsp", roverStatus.version)
installationInstructionsLink!!.visible(true)
} else {
roverVersionLabel!!.component.text = ApolloBundle.message("settings.rover.installed.withLsp", roverStatus.version)
}
}
}

is RoverHelper.RoverStatus.NotInstalled -> {
roverVersionLabel!!.component.text = ApolloBundle.message("settings.rover.notInstalled")
installationInstructionsLink!!.visible(true)
is RoverHelper.RoverStatus.NotInstalled -> {
roverVersionLabel!!.component.text = ApolloBundle.message("settings.rover.notInstalled")
installationInstructionsLink!!.visible(true)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.apollographql.ijplugin.settings.lsp

import com.apollographql.ijplugin.ApolloBundle
import com.apollographql.ijplugin.settings.appSettingsState
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.project.Project
import javax.swing.JComponent

class LspSettingsConfigurable(private val project: Project) : Configurable, Configurable.Beta {
private var settingsComponent: LspSettingsComponent? = null

override fun getDisplayName() = ApolloBundle.message("settings.rover.title")

override fun createComponent(): JComponent {
val settingsComponent = LspSettingsComponent(project)
this.settingsComponent = settingsComponent
return settingsComponent.panel
}

override fun isModified(): Boolean {
return settingsComponent!!.lspModeEnabled != appSettingsState.lspModeEnabled
}

override fun apply() {
appSettingsState.lspModeEnabled = settingsComponent!!.lspModeEnabled
}

override fun reset() {
settingsComponent!!.lspModeEnabled = appSettingsState.lspModeEnabled
}

override fun disposeUIResources() {
settingsComponent = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,16 @@
implementation="com.apollographql.ijplugin.lsp.ApolloLspServerSupportProvider"
/>

<!-- Note: the value of `parentId` corresponds to the settings `id` of the JS GraphQL plugin -->
<!-- See https://github.com/JetBrains/js-graphql-intellij-plugin/blob/396770c293a57f4903acdf427ba5136db6a79d0b/resources/META-INF/plugin.xml#L151 -->
<projectConfigurable
id="com.apollographql.ijplugin.settings.lsp.LspSettingsConfigurable"
parentId="settings.jsgraphql"
instance="com.apollographql.ijplugin.settings.lsp.LspSettingsConfigurable"
key="settings.rover.title"
nonDefaultProject="true"
bundle="messages.ApolloBundle"
/>

</extensions>
</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ settings.rover.checking=Checking for Rover...
settings.rover.installed.withLsp=<html>Rover <b>{0}</b> is installed. ✅
settings.rover.installed.noLsp=<html><font color="#FF8080">Rover <b>{0}</b> is installed, please install version <b>0.27.0</b> or more recent.
settings.rover.notInstalled=<html><font color="#FF8080">Rover doesn\'t seem to be installed.
settings.rover.notInstalled.instructions=Please refer to the <a href=\"https://www.apollographql.com/docs/rover/getting-started\">installation instructions</a>.
settings.rover.notInstalled.instructions=Please refer to the <a href=\"https://www.apollographql.com/docs/rover/getting-started\">installation instructions</a>. Please make sure to install version <b>0.27.0</b> or more recent.
settings.rover.lsp.disabled=Disabled
settings.rover.lsp.disabled.help=Disable the Rover integration. The schema editing experience will rely on the GraphQL plugin's implementation. Recommended for Apollo Kotlin users.
settings.rover.lsp.enabled=Enabled
Expand Down
Loading