From 1ba763bbd4956db661c150bbf86e91352d5b9fbf Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 14 Jan 2025 13:08:04 -0600 Subject: [PATCH 1/5] Initial impl of defaultIde selection setting --- CONTRIBUTING.md | 2 +- .../gateway/CoderSettingsConfigurable.kt | 6 ++++ .../coder/gateway/settings/CoderSettings.kt | 8 +++++ .../steps/CoderWorkspaceProjectIDEStepView.kt | 36 ++++++++++++++++--- .../messages/CoderGatewayBundle.properties | 1 + 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f79e3d82f..50cc8a83e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,7 @@ To simulate opening a workspace from the dashboard pass the Gateway link via `--args`. For example: ``` -./gradlew clean runIDE --args="jetbrains-gateway://connect#type=coder&workspace=dev&agent=coder&folder=/home/coder&url=https://dev.coder.com&token=&ide_product_code=IU&ide_build_number=223.8836.41&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2022.3.3.tar.gz" +./gradlew clean runIDE --args="jetbrains-gateway://connect#type=coder&workspace=bcpeinhardt&owner=benpeinhardt&agent=dev&folder=/home/coder&url=https://dev.coder.com&token=" ``` Alternatively, if you have separately built the plugin and already installed it diff --git a/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt b/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt index 5b69f39eb..52cc4736a 100644 --- a/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt +++ b/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt @@ -149,6 +149,12 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") { .bindText(state::workspaceFilter) .comment(CoderGatewayBundle.message("gateway.connector.settings.workspace-filter.comment")) }.layout(RowLayout.PARENT_GRID) + row(CoderGatewayBundle.message("gateway.connector.settings.default-ide")) { + textField().resizableColumn().align(AlignX.FILL) + .bindText(state::defaultIde) + .comment("The default IDE version to display in the IDE selection dropdown. " + + "Example format: CL 2023.3.6 233.15619.8") + } } } diff --git a/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt b/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt index 4a33a091d..492db8e63 100644 --- a/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt +++ b/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt @@ -100,6 +100,8 @@ open class CoderSettingsState( open var sshLogDirectory: String = "", // Default filter for fetching workspaces open var workspaceFilter: String = "owner:me", + // Default version of IDE to display in IDE selection dropdown + open var defaultIde: String = "", ) /** @@ -174,6 +176,12 @@ open class CoderSettings( val setupCommand: String get() = state.setupCommand + /** + * The default IDE version to display in the selection menu + */ + val defaultIde: String + get() = state.defaultIde + /** * Whether to ignore a failed setup command. */ diff --git a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt index 8478e3558..856f47e50 100644 --- a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt +++ b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt @@ -8,6 +8,7 @@ import com.coder.gateway.models.toIdeWithStatus import com.coder.gateway.models.withWorkspaceProject import com.coder.gateway.sdk.v2.models.Workspace import com.coder.gateway.sdk.v2.models.WorkspaceAgent +import com.coder.gateway.services.CoderSettingsService import com.coder.gateway.util.Arch import com.coder.gateway.util.OS import com.coder.gateway.util.humanizeDuration @@ -20,6 +21,7 @@ import com.coder.gateway.views.LazyBrowserLink import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.asContextElement +import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.ui.ComboBox import com.intellij.openapi.ui.ComponentValidator @@ -54,6 +56,7 @@ import com.jetbrains.gateway.ssh.IdeWithStatus import com.jetbrains.gateway.ssh.IntelliJPlatformProduct import com.jetbrains.gateway.ssh.deploy.DeployException import com.jetbrains.gateway.ssh.util.validateRemotePath +import com.jetbrains.rd.generator.nova.PredefinedType import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -79,6 +82,13 @@ import javax.swing.ListCellRenderer import javax.swing.SwingConstants import javax.swing.event.DocumentEvent +// Just extracting the way we display the IDE info into a helper function. +private fun displayIdeWithStatus(ideWithStatus: IdeWithStatus): String { + return "${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase( + Locale.getDefault(), + )}" +} + /** * View for a single workspace. In particular, show available IDEs and a button * to select an IDE and project to run on the workspace. @@ -88,6 +98,8 @@ class CoderWorkspaceProjectIDEStepView( ) : CoderWizardStep( CoderGatewayBundle.message("gateway.connector.view.coder.remoteproject.next.text"), ) { + private val settings: CoderSettingsService = service() + private val cs = CoroutineScope(Dispatchers.IO) private var ideComboBoxModel = DefaultComboBoxModel() private var state: CoderWorkspacesStepSelection? = null @@ -258,9 +270,24 @@ class CoderWorkspaceProjectIDEStepView( ) }, ) + + // Check the provided setting to see if there's a default IDE to set. + val defaultIde = ides.find { it -> + // Using contains on the displayable version of the ide means they can be as specific or as vague as they want + // CL 2023.3.6 233.15619.8 -> a specific Clion build + // CL 2023.3.6 -> a specific Clion version + // 2023.3.6 -> a specific version (some customers will on have one specific IDE in their list anyway) + if (settings.defaultIde.isEmpty()) { + false + } else { + displayIdeWithStatus(it).contains(settings.defaultIde) + } + } + val index = ides.indexOf(defaultIde ?: ides.firstOrNull()) + withContext(Dispatchers.IO) { ideComboBoxModel.addAll(ides) - cbIDE.selectedIndex = 0 + cbIDE.selectedIndex = index } } catch (e: Exception) { if (isCancellation(e)) { @@ -456,10 +483,9 @@ class CoderWorkspaceProjectIDEStepView( layout = FlowLayout(FlowLayout.LEFT) add(JLabel(ideWithStatus.product.ideName, ideWithStatus.product.icon, SwingConstants.LEFT)) add( - JLabel( - "${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase( - Locale.getDefault(), - )}", + JLabel(displayIdeWithStatus( + ideWithStatus + ), ).apply { foreground = UIUtil.getLabelDisabledForeground() }, diff --git a/src/main/resources/messages/CoderGatewayBundle.properties b/src/main/resources/messages/CoderGatewayBundle.properties index 0f684b719..71000593b 100644 --- a/src/main/resources/messages/CoderGatewayBundle.properties +++ b/src/main/resources/messages/CoderGatewayBundle.properties @@ -138,3 +138,4 @@ gateway.connector.settings.workspace-filter.comment=The filter to apply when \ the plugin fetches resources individually for each non-running workspace, \ which can be slow with many workspaces, and it adds every agent to the SSH \ config, which can result in a large SSH config with many workspaces. +gateway.connector.settings.default-ide=Default IDE Selection From 5ba242c543f7f419ba3fb0c0cec62c11bd37ff67 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 17 Jan 2025 13:10:21 -0600 Subject: [PATCH 2/5] Reset example url in readme --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 50cc8a83e..f79e3d82f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,7 @@ To simulate opening a workspace from the dashboard pass the Gateway link via `--args`. For example: ``` -./gradlew clean runIDE --args="jetbrains-gateway://connect#type=coder&workspace=bcpeinhardt&owner=benpeinhardt&agent=dev&folder=/home/coder&url=https://dev.coder.com&token=" +./gradlew clean runIDE --args="jetbrains-gateway://connect#type=coder&workspace=dev&agent=coder&folder=/home/coder&url=https://dev.coder.com&token=&ide_product_code=IU&ide_build_number=223.8836.41&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2022.3.3.tar.gz" ``` Alternatively, if you have separately built the plugin and already installed it From cc260fa8108f1d1e9939cfeca1c3177673bb2a77 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 17 Jan 2025 16:05:19 -0600 Subject: [PATCH 3/5] Selected KT Lint changes. --- .../coder/gateway/CoderSettingsConfigurable.kt | 8 +++++--- .../steps/CoderWorkspaceProjectIDEStepView.kt | 16 +++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt b/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt index 52cc4736a..9bd023506 100644 --- a/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt +++ b/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt @@ -151,9 +151,11 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") { }.layout(RowLayout.PARENT_GRID) row(CoderGatewayBundle.message("gateway.connector.settings.default-ide")) { textField().resizableColumn().align(AlignX.FILL) - .bindText(state::defaultIde) - .comment("The default IDE version to display in the IDE selection dropdown. " + - "Example format: CL 2023.3.6 233.15619.8") + .bindText(state::defaultIde) + .comment( + "The default IDE version to display in the IDE selection dropdown. " + + "Example format: CL 2023.3.6 233.15619.8", + ) } } } diff --git a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt index 856f47e50..76f207031 100644 --- a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt +++ b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt @@ -56,7 +56,6 @@ import com.jetbrains.gateway.ssh.IdeWithStatus import com.jetbrains.gateway.ssh.IntelliJPlatformProduct import com.jetbrains.gateway.ssh.deploy.DeployException import com.jetbrains.gateway.ssh.util.validateRemotePath -import com.jetbrains.rd.generator.nova.PredefinedType import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -83,11 +82,9 @@ import javax.swing.SwingConstants import javax.swing.event.DocumentEvent // Just extracting the way we display the IDE info into a helper function. -private fun displayIdeWithStatus(ideWithStatus: IdeWithStatus): String { - return "${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase( - Locale.getDefault(), - )}" -} +private fun displayIdeWithStatus(ideWithStatus: IdeWithStatus): String = "${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase( + Locale.getDefault(), +)}" /** * View for a single workspace. In particular, show available IDEs and a button @@ -483,9 +480,10 @@ class CoderWorkspaceProjectIDEStepView( layout = FlowLayout(FlowLayout.LEFT) add(JLabel(ideWithStatus.product.ideName, ideWithStatus.product.icon, SwingConstants.LEFT)) add( - JLabel(displayIdeWithStatus( - ideWithStatus - ), + JLabel( + displayIdeWithStatus( + ideWithStatus, + ), ).apply { foreground = UIUtil.getLabelDisabledForeground() }, From 2214c99fe2c22940de14a86fbcd55e0b22ab2400 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 17 Jan 2025 16:12:34 -0600 Subject: [PATCH 4/5] Fix typo. --- .../gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt index 76f207031..697090183 100644 --- a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt +++ b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt @@ -273,7 +273,7 @@ class CoderWorkspaceProjectIDEStepView( // Using contains on the displayable version of the ide means they can be as specific or as vague as they want // CL 2023.3.6 233.15619.8 -> a specific Clion build // CL 2023.3.6 -> a specific Clion version - // 2023.3.6 -> a specific version (some customers will on have one specific IDE in their list anyway) + // 2023.3.6 -> a specific version (some customers will only have one specific IDE in their list anyway) if (settings.defaultIde.isEmpty()) { false } else { From 7d76e4ff9f86a12981c6588cb542019f17d3be45 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 17 Jan 2025 16:18:25 -0600 Subject: [PATCH 5/5] Update changelog. --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33c142368..6bb233372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ ## Unreleased +### Added + +- Added setting "Default IDE Selection" which will look for a matching IDE + code/version/build number to set as the preselected IDE in the select + component. + ## 2.15.2 - 2025-01-06 ### Changed