Skip to content

Initial impl of defaultIde selection setting #522

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

Merged
merged 5 commits into from
Jan 17, 2025
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ 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",
)
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
)

/**
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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
Expand All @@ -20,6 +21,7 @@
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
Expand Down Expand Up @@ -79,6 +81,11 @@
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 = "${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.
Expand All @@ -88,6 +95,8 @@
) : CoderWizardStep<WorkspaceProjectIDE>(
CoderGatewayBundle.message("gateway.connector.view.coder.remoteproject.next.text"),
) {
private val settings: CoderSettingsService = service<CoderSettingsService>()

private val cs = CoroutineScope(Dispatchers.IO)
private var ideComboBoxModel = DefaultComboBoxModel<IdeWithStatus>()
private var state: CoderWorkspacesStepSelection? = null
Expand Down Expand Up @@ -258,9 +267,24 @@
)
},
)

// Check the provided setting to see if there's a default IDE to set.
val defaultIde = ides.find { it ->

Check notice on line 272 in src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant lambda arrow

Redundant lambda arrow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qodana will complain about it -> since that is the default, although idk how much we should care about Qodana. Possibly ktlint would change this automatically.

Tangent, but I think there is an alias for find called firstOrNull. Kinda surprised there is no indexOfFirstOrNull, only indexOfFirst. indexOfFirst().takeIf { it >= 0 } would work around that I guess.

Anyway, no need to change to those, more that I nerd sniped myself. 😆

// 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 only 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)) {
Expand Down Expand Up @@ -457,9 +481,9 @@
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(),
)}",
displayIdeWithStatus(
ideWithStatus,
),
).apply {
foreground = UIUtil.getLabelDisabledForeground()
},
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/CoderGatewayBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading