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 2 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 @@ -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. " +
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we need to make mention that JetBrains by default only shows the latest version (latest stable and latest EAP I think, right?), so as soon as JetBrains updates their list this setting may become obsolete unless they are using just the IDE name or year.

But, maybe this option will only be used by folks that have provided their own list instead of fetching from JetBrains, so that might not be an issue.

"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 @@ -54,6 +56,7 @@
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

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

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
Copy link
Member

Choose a reason for hiding this comment

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

You probably already see the warning but appears to be unused (I think ktlint will delete unused imports if you want to try using that)

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -79,6 +82,13 @@
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.
Expand All @@ -88,6 +98,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 +270,24 @@
)
},
)

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

Check notice on line 275 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 on have one specific IDE in their list anyway)
Copy link
Member

Choose a reason for hiding this comment

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

Typo I think in will on have (will only have maybe)

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 @@ -456,10 +483,9 @@
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()
},
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