Skip to content

Commit 308b9ff

Browse files
committed
make blockContent empty on no workspaces
1 parent 72512e3 commit 308b9ff

File tree

6 files changed

+102
-110
lines changed

6 files changed

+102
-110
lines changed

src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,11 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") {
167167
}
168168
}
169169

170-
private fun validateDataDirectory(): ValidationInfoBuilder.(JBTextField) -> ValidationInfo? =
171-
{
172-
if (it.text.isNotBlank() && !Path.of(it.text).canCreateDirectory()) {
173-
error("Cannot create this directory")
174-
} else {
175-
null
176-
}
170+
private fun validateDataDirectory(): ValidationInfoBuilder.(JBTextField) -> ValidationInfo? = {
171+
if (it.text.isNotBlank() && !Path.of(it.text).canCreateDirectory()) {
172+
error("Cannot create this directory")
173+
} else {
174+
null
177175
}
176+
}
178177
}

src/main/kotlin/com/coder/gateway/cli/CoderCLIManager.kt

+45-49
Original file line numberDiff line numberDiff line change
@@ -307,35 +307,36 @@ class CoderCLIManager(
307307
Host ${getHostPrefix()}-bg--*
308308
ProxyCommand ${backgroundProxyArgs.joinToString(" ")} --ssh-host-prefix ${getHostPrefix()}-bg-- %h
309309
""".trimIndent()
310-
.plus("\n" + sshOpts.prependIndent(" "))
311-
.plus(extraConfig),
310+
.plus("\n" + sshOpts.prependIndent(" "))
311+
.plus(extraConfig),
312312
).replace("\n", System.lineSeparator()) +
313313
System.lineSeparator() + endBlock
314-
315-
} else {
316-
workspaceNames.joinToString(
317-
System.lineSeparator(),
318-
startBlock + System.lineSeparator(),
319-
System.lineSeparator() + endBlock,
320-
transform = {
321-
"""
314+
} else if (workspaceNames.isEmpty()) {
315+
""
316+
} else {
317+
workspaceNames.joinToString(
318+
System.lineSeparator(),
319+
startBlock + System.lineSeparator(),
320+
System.lineSeparator() + endBlock,
321+
transform = {
322+
"""
322323
Host ${getHostName(it.first, currentUser, it.second)}
323324
ProxyCommand ${proxyArgs.joinToString(" ")} ${getWorkspaceParts(it.first, it.second)}
324-
""".trimIndent()
325-
.plus("\n" + sshOpts.prependIndent(" "))
326-
.plus(extraConfig)
327-
.plus("\n")
328-
.plus(
329-
"""
325+
""".trimIndent()
326+
.plus("\n" + sshOpts.prependIndent(" "))
327+
.plus(extraConfig)
328+
.plus("\n")
329+
.plus(
330+
"""
330331
Host ${getBackgroundHostName(it.first, currentUser, it.second)}
331332
ProxyCommand ${backgroundProxyArgs.joinToString(" ")} ${getWorkspaceParts(it.first, it.second)}
332-
""".trimIndent()
333-
.plus("\n" + sshOpts.prependIndent(" "))
334-
.plus(extraConfig),
335-
).replace("\n", System.lineSeparator())
336-
},
337-
)
338-
}
333+
""".trimIndent()
334+
.plus("\n" + sshOpts.prependIndent(" "))
335+
.plus(extraConfig),
336+
).replace("\n", System.lineSeparator())
337+
},
338+
)
339+
}
339340

340341
if (contents == null) {
341342
logger.info("No existing SSH config to modify")
@@ -478,15 +479,13 @@ class CoderCLIManager(
478479
*
479480
* Throws if the command execution fails.
480481
*/
481-
fun startWorkspace(workspaceOwner: String, workspaceName: String): String {
482-
return exec(
483-
"--global-config",
484-
coderConfigPath.toString(),
485-
"start",
486-
"--yes",
487-
workspaceOwner+"/"+workspaceName,
488-
)
489-
}
482+
fun startWorkspace(workspaceOwner: String, workspaceName: String): String = exec(
483+
"--global-config",
484+
coderConfigPath.toString(),
485+
"start",
486+
"--yes",
487+
workspaceOwner + "/" + workspaceName,
488+
)
490489

491490
private fun exec(vararg args: String): String {
492491
val stdout =
@@ -519,8 +518,7 @@ class CoderCLIManager(
519518
/*
520519
* This function returns the ssh-host-prefix used for Host entries.
521520
*/
522-
fun getHostPrefix(): String =
523-
"coder-jetbrains-${deploymentURL.safeHost()}"
521+
fun getHostPrefix(): String = "coder-jetbrains-${deploymentURL.safeHost()}"
524522

525523
/**
526524
* This function returns the ssh host name generated for connecting to the workspace.
@@ -529,29 +527,27 @@ class CoderCLIManager(
529527
workspace: Workspace,
530528
currentUser: User,
531529
agent: WorkspaceAgent,
532-
): String =
533-
if (features.wildcardSSH) {
534-
"${getHostPrefix()}--${workspace.ownerName}--${workspace.name}.${agent.name}"
530+
): String = if (features.wildcardSSH) {
531+
"${getHostPrefix()}--${workspace.ownerName}--${workspace.name}.${agent.name}"
532+
} else {
533+
// For a user's own workspace, we use the old syntax without a username for backwards compatibility,
534+
// since the user might have recent connections that still use the old syntax.
535+
if (currentUser.username == workspace.ownerName) {
536+
"coder-jetbrains--${workspace.name}.${agent.name}--${deploymentURL.safeHost()}"
535537
} else {
536-
// For a user's own workspace, we use the old syntax without a username for backwards compatibility,
537-
// since the user might have recent connections that still use the old syntax.
538-
if (currentUser.username == workspace.ownerName) {
539-
"coder-jetbrains--${workspace.name}.${agent.name}--${deploymentURL.safeHost()}"
540-
} else {
541-
"coder-jetbrains--${workspace.ownerName}--${workspace.name}.${agent.name}--${deploymentURL.safeHost()}"
538+
"coder-jetbrains--${workspace.ownerName}--${workspace.name}.${agent.name}--${deploymentURL.safeHost()}"
542539
}
543540
}
544541

545542
fun getBackgroundHostName(
546543
workspace: Workspace,
547544
currentUser: User,
548545
agent: WorkspaceAgent,
549-
): String =
550-
if (features.wildcardSSH) {
551-
"${getHostPrefix()}-bg--${workspace.ownerName}--${workspace.name}.${agent.name}"
552-
} else {
553-
getHostName(workspace, currentUser, agent) + "--bg"
554-
}
546+
): String = if (features.wildcardSSH) {
547+
"${getHostPrefix()}-bg--${workspace.ownerName}--${workspace.name}.${agent.name}"
548+
} else {
549+
getHostName(workspace, currentUser, agent) + "--bg"
550+
}
555551

556552
companion object {
557553
val logger = Logger.getInstance(CoderCLIManager::class.java.simpleName)

src/main/kotlin/com/coder/gateway/icons/CoderIcons.kt

+41-42
Original file line numberDiff line numberDiff line change
@@ -63,48 +63,47 @@ object CoderIcons {
6363
private val Y = IconLoader.getIcon("symbols/y.svg", javaClass)
6464
private val Z = IconLoader.getIcon("symbols/z.svg", javaClass)
6565

66-
fun fromChar(c: Char) =
67-
when (c) {
68-
'0' -> ZERO
69-
'1' -> ONE
70-
'2' -> TWO
71-
'3' -> THREE
72-
'4' -> FOUR
73-
'5' -> FIVE
74-
'6' -> SIX
75-
'7' -> SEVEN
76-
'8' -> EIGHT
77-
'9' -> NINE
78-
79-
'a' -> A
80-
'b' -> B
81-
'c' -> C
82-
'd' -> D
83-
'e' -> E
84-
'f' -> F
85-
'g' -> G
86-
'h' -> H
87-
'i' -> I
88-
'j' -> J
89-
'k' -> K
90-
'l' -> L
91-
'm' -> M
92-
'n' -> N
93-
'o' -> O
94-
'p' -> P
95-
'q' -> Q
96-
'r' -> R
97-
's' -> S
98-
't' -> T
99-
'u' -> U
100-
'v' -> V
101-
'w' -> W
102-
'x' -> X
103-
'y' -> Y
104-
'z' -> Z
105-
106-
else -> UNKNOWN
107-
}
66+
fun fromChar(c: Char) = when (c) {
67+
'0' -> ZERO
68+
'1' -> ONE
69+
'2' -> TWO
70+
'3' -> THREE
71+
'4' -> FOUR
72+
'5' -> FIVE
73+
'6' -> SIX
74+
'7' -> SEVEN
75+
'8' -> EIGHT
76+
'9' -> NINE
77+
78+
'a' -> A
79+
'b' -> B
80+
'c' -> C
81+
'd' -> D
82+
'e' -> E
83+
'f' -> F
84+
'g' -> G
85+
'h' -> H
86+
'i' -> I
87+
'j' -> J
88+
'k' -> K
89+
'l' -> L
90+
'm' -> M
91+
'n' -> N
92+
'o' -> O
93+
'p' -> P
94+
'q' -> Q
95+
'r' -> R
96+
's' -> S
97+
't' -> T
98+
'u' -> U
99+
'v' -> V
100+
'w' -> W
101+
'x' -> X
102+
'y' -> Y
103+
'z' -> Z
104+
105+
else -> UNKNOWN
106+
}
108107
}
109108

110109
fun alignToInt(g: Graphics) {

src/main/kotlin/com/coder/gateway/models/WorkspaceAndAgentStatus.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
4747
READY("Ready", "The agent is ready to accept connections."),
4848
;
4949

50-
fun statusColor(): JBColor =
51-
when (this) {
52-
READY, AGENT_STARTING_READY, START_TIMEOUT_READY -> JBColor.GREEN
53-
CREATED, START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW
54-
FAILED, DISCONNECTED, TIMEOUT, SHUTDOWN_ERROR -> JBColor.RED
55-
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
56-
}
50+
fun statusColor(): JBColor = when (this) {
51+
READY, AGENT_STARTING_READY, START_TIMEOUT_READY -> JBColor.GREEN
52+
CREATED, START_ERROR, START_TIMEOUT, SHUTDOWN_TIMEOUT -> JBColor.YELLOW
53+
FAILED, DISCONNECTED, TIMEOUT, SHUTDOWN_ERROR -> JBColor.RED
54+
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
55+
}
5756

5857
/**
5958
* Return true if the agent is in a connectable state.

src/main/kotlin/com/coder/gateway/sdk/convertors/InstantConverter.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ import java.time.temporal.TemporalAccessor
1212
class InstantConverter {
1313
@ToJson fun toJson(src: Instant?): String = FORMATTER.format(src)
1414

15-
@FromJson fun fromJson(src: String): Instant? =
16-
FORMATTER.parse(src) { temporal: TemporalAccessor? ->
17-
Instant.from(temporal)
18-
}
15+
@FromJson fun fromJson(src: String): Instant? = FORMATTER.parse(src) { temporal: TemporalAccessor? ->
16+
Instant.from(temporal)
17+
}
1918

2019
companion object {
2120
private val FORMATTER = DateTimeFormatter.ISO_INSTANT

src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ open class CoderSettings(
188188
* Whether to check for IDE updates.
189189
*/
190190
val checkIDEUpdate: Boolean
191-
get() = state.checkIDEUpdates
191+
get() = state.checkIDEUpdates
192192

193193
/**
194194
* Whether to ignore a failed setup command.

0 commit comments

Comments
 (0)