Skip to content

Commit 4d99a80

Browse files
committed
tst
1 parent 855afd6 commit 4d99a80

File tree

8 files changed

+188
-142
lines changed

8 files changed

+188
-142
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/flareChat/ChatCommunicationManager.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ class ChatCommunicationManager {
108108
reauthConnectionIfNeeded(project, it, isReAuth = true)
109109
}
110110
when (incomingType) {
111-
AuthFollowupType.USE_SUPPORTED_AUTH.value -> {
111+
AuthFollowupType.USE_SUPPORTED_AUTH -> {
112112
project.messageBus.syncPublisher(QRegionProfileSelectedListener.TOPIC)
113113
.onProfileSelected(project, QRegionProfileManager.getInstance().activeProfile(project))
114114
return
115115
}
116-
AuthFollowupType.RE_AUTH.value,
117-
AuthFollowupType.MISSING_SCOPES.value,
118-
AuthFollowupType.FULL_AUTH.value,
116+
AuthFollowupType.RE_AUTH,
117+
AuthFollowupType.MISSING_SCOPES,
118+
AuthFollowupType.FULL_AUTH,
119119
-> {
120120
return
121121
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model
5+
6+
import com.fasterxml.jackson.annotation.JsonValue
7+
import com.google.gson.Gson
8+
import com.google.gson.TypeAdapter
9+
import com.google.gson.TypeAdapterFactory
10+
import com.google.gson.reflect.TypeToken
11+
12+
/**
13+
* A [Gson] [TypeAdapterFactory] that uses Jackson @[JsonValue] instead of [Enum.name] for de/serialization
14+
*/
15+
class EnumJsonValueAdapter : TypeAdapterFactory {
16+
override fun <T> create(
17+
gson: Gson,
18+
type: TypeToken<T>
19+
): TypeAdapter<T>? {
20+
val rawType = type.getRawType()
21+
if (!rawType.isEnum) {
22+
return null
23+
}
24+
25+
val jsonField = rawType.declaredFields.firstOrNull { it.isAnnotationPresent(JsonValue::class.java) }
26+
?: return null
27+
28+
jsonField.isAccessible = true
29+
30+
return object : TypeAdapter<T>() {
31+
override fun write(out: com.google.gson.stream.JsonWriter, value: T) {
32+
val result = jsonField.get(value) as Any
33+
(gson.getAdapter(result::class.java) as TypeAdapter<Any>).write(out, result)
34+
}
35+
36+
override fun read(`in`: com.google.gson.stream.JsonReader): T {
37+
val jsonValue = `in`.nextString()
38+
return rawType.enumConstants.first { jsonField.get(it).toString() == jsonValue } as T
39+
}
40+
} as TypeAdapter<T>
41+
}
42+
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/AuthFollowUpClicked.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat
55

6+
import com.fasterxml.jackson.annotation.JsonValue
7+
import com.google.gson.annotations.JsonAdapter
8+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.EnumJsonValueAdapter
9+
610
data class AuthFollowUpClickNotification(
711
override val command: String,
812
override val params: AuthFollowUpClickedParams,
@@ -11,21 +15,14 @@ data class AuthFollowUpClickNotification(
1115
data class AuthFollowUpClickedParams(
1216
val tabId: String,
1317
val messageId: String,
14-
val authFollowupType: String,
15-
) {
16-
companion object {
17-
fun create(tabId: String, messageId: String, authType: AuthFollowupType): AuthFollowUpClickedParams =
18-
AuthFollowUpClickedParams(tabId, messageId, authType.value)
19-
}
20-
}
18+
val authFollowupType: AuthFollowupType,
19+
)
2120

22-
enum class AuthFollowupType(val value: String) {
21+
@JsonAdapter(EnumJsonValueAdapter::class)
22+
enum class AuthFollowupType(@JsonValue val repr: String) {
2323
FULL_AUTH("full-auth"),
2424
RE_AUTH("re-auth"),
2525
MISSING_SCOPES("missing_scopes"),
2626
USE_SUPPORTED_AUTH("use-supported-auth"),
2727
;
28-
29-
override fun toString(): String =
30-
name.lowercase()
3128
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

Lines changed: 39 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat
55

6-
import com.fasterxml.jackson.annotation.JsonProperty
6+
import com.fasterxml.jackson.annotation.JsonValue
7+
import com.google.gson.annotations.JsonAdapter
8+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.EnumJsonValueAdapter
79

810
data class ChatMessage(
911
val type: MessageType? = MessageType.ANSWER,
@@ -69,93 +71,51 @@ data class Changes(
6971
val total: Int? = null,
7072
)
7173

72-
enum class IconType {
73-
@JsonProperty("file")
74-
FILE,
75-
76-
@JsonProperty("folder")
77-
FOLDER,
78-
79-
@JsonProperty("code-block")
80-
CODE_BLOCK,
81-
82-
@JsonProperty("list-add")
83-
LIST_ADD,
84-
85-
@JsonProperty("magic")
86-
MAGIC,
87-
88-
@JsonProperty("help")
89-
HELP,
90-
91-
@JsonProperty("trash")
92-
TRASH,
93-
94-
@JsonProperty("search")
95-
SEARCH,
96-
97-
@JsonProperty("calendar")
98-
CALENDAR,
74+
@JsonAdapter(EnumJsonValueAdapter::class)
75+
enum class IconType(@JsonValue val repr: String) {
76+
FILE("file"),
77+
FOLDER("folder"),
78+
CODE_BLOCK("code-block"),
79+
LIST_ADD("list-add"),
80+
MAGIC("magic"),
81+
HELP("help"),
82+
TRASH("trash"),
83+
SEARCH("search"),
84+
CALENDAR("calendar"),
9985
;
10086

101-
companion object {
102-
private val stringToEnum: Map<String, IconType> = entries.associateBy { it.name.lowercase() }
103-
104-
fun fromString(value: String): IconType = stringToEnum[value] ?: throw IllegalArgumentException("Unknown IconType: $value")
105-
}
10687
}
10788

108-
enum class Status {
109-
@JsonProperty("info")
110-
INFO,
111-
112-
@JsonProperty("success")
113-
SUCCESS,
114-
115-
@JsonProperty("warning")
116-
WARNING,
89+
@JsonAdapter(EnumJsonValueAdapter::class)
90+
enum class Status(@JsonValue val repr: String) {
91+
INFO("info"),
92+
SUCCESS("success"),
93+
WARNING("warning"),
94+
ERROR("error"),
95+
;
11796

118-
@JsonProperty("error")
119-
ERROR,
12097
}
12198

122-
enum class ButtonStatus {
123-
@JsonProperty("main")
124-
MAIN,
125-
126-
@JsonProperty("primary")
127-
PRIMARY,
128-
129-
@JsonProperty("clear")
130-
CLEAR,
131-
132-
@JsonProperty("info")
133-
INFO,
134-
135-
@JsonProperty("success")
136-
SUCCESS,
137-
138-
@JsonProperty("warning")
139-
WARNING,
99+
@JsonAdapter(EnumJsonValueAdapter::class)
100+
enum class ButtonStatus(@JsonValue val repr: String) {
101+
MAIN("main"),
102+
PRIMARY("primary"),
103+
CLEAR("clear"),
104+
INFO("info"),
105+
SUCCESS("success"),
106+
WARNING("warning"),
107+
ERROR("error"),
108+
;
140109

141-
@JsonProperty("error")
142-
ERROR,
143110
}
144111

145112
// https://github.com/aws/language-server-runtimes/blame/68319c975d29a8ba9b084c9fa780ebff75b286bb/types/chat.ts#L127
146-
enum class MessageType {
147-
@JsonProperty("answer")
148-
ANSWER,
149-
150-
@JsonProperty("prompt")
151-
PROMPT,
152-
153-
@JsonProperty("system-prompt")
154-
SYSTEM_PROMPT,
155-
156-
@JsonProperty("directive")
157-
DIRECTIVE,
158-
159-
@JsonProperty("tool")
160-
TOOL,
113+
@JsonAdapter(EnumJsonValueAdapter::class)
114+
enum class MessageType(@JsonValue val repr: String) {
115+
ANSWER("answer"),
116+
PROMPT("prompt"),
117+
SYSTEM_PROMPT("system-prompt"),
118+
DIRECTIVE("directive"),
119+
TOOL("tool"),
120+
;
161121
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/Conversations.kt

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat
55

6-
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
7-
// SPDX-License-Identifier: Apache-2.0
6+
import com.fasterxml.jackson.annotation.JsonValue
7+
import com.google.gson.annotations.JsonAdapter
8+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.EnumJsonValueAdapter
89

910
typealias FilterValue = String
1011

1112
data class TextBasedFilterOption(
1213
val type: String,
1314
val placeholder: String?,
1415
val icon: IconType?,
15-
) {
16-
companion object {
17-
fun create(type: TextInputType, placeholder: String, icon: IconType): TextBasedFilterOption =
18-
TextBasedFilterOption(type.value, placeholder, icon)
19-
}
20-
}
16+
)
2117

2218
data class FilterOption(
2319
val id: String,
@@ -61,43 +57,30 @@ data class ConversationsList(
6157

6258
typealias ListConversationsResult = ConversationsList
6359

64-
enum class TextInputType(val value: String) {
60+
@JsonAdapter(EnumJsonValueAdapter::class)
61+
enum class TextInputType(@JsonValue val repr: String) {
6562
TEXTAREA("textarea"),
6663
TEXTINPUT("textinput"),
6764
;
68-
69-
override fun toString(): String =
70-
name.lowercase()
7165
}
7266

73-
enum class ConversationAction(val value: String) {
67+
@JsonAdapter(EnumJsonValueAdapter::class)
68+
enum class ConversationAction(@JsonValue val repr: String) {
7469
DELETE("delete"),
7570
EXPORT("markdown"),
7671
;
77-
78-
override fun toString(): String =
79-
name.lowercase()
8072
}
73+
8174
data class ConversationClickParams(
8275
val id: String,
8376
val action: String?,
84-
) {
85-
companion object {
86-
fun create(id: String, action: ConversationAction): ConversationClickParams =
87-
ConversationClickParams(id, action.value)
88-
}
89-
}
77+
)
9078

9179
data class ConversationClickResult(
9280
val id: String,
9381
val action: String?,
9482
val success: Boolean,
95-
) {
96-
companion object {
97-
fun create(id: String, action: ConversationAction, success: Boolean): ConversationClickResult =
98-
ConversationClickResult(id, action.value, success)
99-
}
100-
}
83+
)
10184

10285
data class ListConversationsRequest(
10386
override val command: String,

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/GetSerializedChatParams.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat
55

6+
import com.fasterxml.jackson.annotation.JsonValue
7+
import com.google.gson.annotations.JsonAdapter
8+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.EnumJsonValueAdapter
9+
610
data class GetSerializedChatParams(
711
val tabId: String,
812
val format: String,
9-
) {
10-
companion object {
11-
fun create(tabId: String, format: SerializedChatFormat): GetSerializedChatParams =
12-
GetSerializedChatParams(tabId, format.value)
13-
}
14-
}
13+
)
1514

16-
enum class SerializedChatFormat(val value: String) {
15+
@JsonAdapter(EnumJsonValueAdapter::class)
16+
enum class SerializedChatFormat(@JsonValue val repr: String) {
1717
HTML("html"),
1818
MARKDOWN("markdown"),
1919
;
20-
21-
override fun toString(): String =
22-
name.lowercase()
2320
}
2421

2522
data class GetSerializedChatResult(

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/TabBarActionParams.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat
55

6+
import com.fasterxml.jackson.annotation.JsonValue
7+
import com.google.gson.annotations.JsonAdapter
8+
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.EnumJsonValueAdapter
9+
610
data class TabBarActionParams(
711
val tabId: String?,
812
val action: String,
9-
) {
10-
companion object {
11-
fun create(tabId: String?, action: TabBarAction): TabBarActionParams =
12-
TabBarActionParams(tabId, action.value)
13-
}
14-
}
13+
)
1514

16-
enum class TabBarAction(val value: String) {
15+
@JsonAdapter(EnumJsonValueAdapter::class)
16+
enum class TabBarAction(@JsonValue val repr: String) {
1717
EXPORT("export"),
1818
;
19-
20-
override fun toString(): String =
21-
name.lowercase()
2219
}
2320

2421
data class TabBarActionResult(

0 commit comments

Comments
 (0)