Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -9,13 +9,10 @@ import org.eclipse.lsp4j.services.LanguageClient
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.LSPAny
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.CHAT_SEND_CONTEXT_COMMANDS
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.CHAT_SEND_UPDATE
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ChatUpdateParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GET_SERIALIZED_CHAT_REQUEST_METHOD
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GetSerializedChatParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GetSerializedChatResult
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.OPEN_FILE_DIFF
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.OpenFileDiffParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.OpenTabParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.OpenTabResult
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.SHOW_SAVE_FILE_DIALOG_REQUEST_METHOD
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ShowSaveFileDialogParams
Expand All @@ -32,16 +29,16 @@ interface AmazonQLanguageClient : LanguageClient {
fun getConnectionMetadata(): CompletableFuture<ConnectionMetadata>

@JsonRequest("aws/chat/openTab")
fun openTab(params: OpenTabParams): CompletableFuture<OpenTabResult>
fun openTab(params: LSPAny): CompletableFuture<OpenTabResult>

@JsonRequest(SHOW_SAVE_FILE_DIALOG_REQUEST_METHOD)
fun showSaveFileDialog(params: ShowSaveFileDialogParams): CompletableFuture<ShowSaveFileDialogResult>

@JsonRequest(GET_SERIALIZED_CHAT_REQUEST_METHOD)
fun getSerializedChat(params: GetSerializedChatParams): CompletableFuture<GetSerializedChatResult>
fun getSerializedChat(params: LSPAny): CompletableFuture<GetSerializedChatResult>

@JsonNotification(CHAT_SEND_UPDATE)
fun sendChatUpdate(params: ChatUpdateParams): CompletableFuture<Unit>
fun sendChatUpdate(params: LSPAny): CompletableFuture<Unit>

@JsonNotification(OPEN_FILE_DIFF)
fun openFileDiff(params: OpenFileDiffParams): CompletableFuture<Unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.LSPAny
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.CHAT_OPEN_TAB
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.CHAT_SEND_CONTEXT_COMMANDS
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.CHAT_SEND_UPDATE
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ChatUpdateParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GET_SERIALIZED_CHAT_REQUEST_METHOD
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GetSerializedChatParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GetSerializedChatResult
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.OpenFileDiffParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.OpenTabParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.OpenTabResult
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ShowSaveFileDialogParams
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.ShowSaveFileDialogResult
Expand Down Expand Up @@ -134,7 +131,7 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
}
}

override fun openTab(params: OpenTabParams): CompletableFuture<OpenTabResult> {
override fun openTab(params: LSPAny): CompletableFuture<OpenTabResult> {
val requestId = UUID.randomUUID().toString()
val result = CompletableFuture<OpenTabResult>()
val chatManager = ChatCommunicationManager.getInstance(project)
Expand Down Expand Up @@ -186,7 +183,7 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
)
}

override fun getSerializedChat(params: GetSerializedChatParams): CompletableFuture<GetSerializedChatResult> {
override fun getSerializedChat(params: LSPAny): CompletableFuture<GetSerializedChatResult> {
val requestId = UUID.randomUUID().toString()
val result = CompletableFuture<GetSerializedChatResult>()
val chatManager = ChatCommunicationManager.getInstance(project)
Expand Down Expand Up @@ -261,7 +258,7 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
}
}

override fun sendChatUpdate(params: ChatUpdateParams): CompletableFuture<Unit> {
override fun sendChatUpdate(params: LSPAny): CompletableFuture<Unit> {
AsyncChatUiListener.notifyPartialMessageUpdate(
FlareUiMessage(
command = CHAT_SEND_UPDATE,
Expand Down Expand Up @@ -345,7 +342,7 @@ class AmazonQLanguageClientImpl(private val project: Project) : AmazonQLanguageC
chatManager.notifyUi(
FlareUiMessage(
command = CHAT_SEND_CONTEXT_COMMANDS,
params = params ?: error("received empty payload for $CHAT_SEND_CONTEXT_COMMANDS"),
params = params,
)
)
return CompletableFuture.completedFuture(Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ class ChatCommunicationManager(private val cs: CoroutineScope) {
reauthConnectionIfNeeded(project, it, isReAuth = true)
}
when (incomingType) {
AuthFollowupType.USE_SUPPORTED_AUTH.value -> {
AuthFollowupType.USE_SUPPORTED_AUTH -> {
project.messageBus.syncPublisher(QRegionProfileSelectedListener.TOPIC)
.onProfileSelected(project, QRegionProfileManager.getInstance().activeProfile(project))
return
}
AuthFollowupType.RE_AUTH.value,
AuthFollowupType.MISSING_SCOPES.value,
AuthFollowupType.FULL_AUTH.value,
AuthFollowupType.RE_AUTH,
AuthFollowupType.MISSING_SCOPES,
AuthFollowupType.FULL_AUTH,
-> {
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.services.amazonq.lsp.model

import com.fasterxml.jackson.annotation.JsonValue
import com.google.gson.Gson
import com.google.gson.TypeAdapter
import com.google.gson.TypeAdapterFactory
import com.google.gson.reflect.TypeToken

/**
* A [Gson] [TypeAdapterFactory] that uses Jackson @[JsonValue] instead of [Enum.name] for de/serialization
*/
class EnumJsonValueAdapter : TypeAdapterFactory {
override fun <T> create(
gson: Gson,
type: TypeToken<T>
): TypeAdapter<T>? {
val rawType = type.getRawType()
if (!rawType.isEnum) {
return null
}

val jsonField = rawType.declaredFields.firstOrNull { it.isAnnotationPresent(JsonValue::class.java) }
?: return null

jsonField.isAccessible = true

return object : TypeAdapter<T>() {
override fun write(out: com.google.gson.stream.JsonWriter, value: T) {
val result = jsonField.get(value) as Any
(gson.getAdapter(result::class.java) as TypeAdapter<Any>).write(out, result)
}

override fun read(`in`: com.google.gson.stream.JsonReader): T {
val jsonValue = `in`.nextString()
return rawType.enumConstants.first { jsonField.get(it).toString() == jsonValue } as T
}
} as TypeAdapter<T>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ data class UpdateConfigurationParams(
val settings: LSPAny,
)

typealias LSPAny = Any?
typealias LSPAny = Any
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

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

import com.fasterxml.jackson.annotation.JsonValue
import com.google.gson.annotations.JsonAdapter
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.EnumJsonValueAdapter

data class AuthFollowUpClickNotification(
override val command: String,
override val params: AuthFollowUpClickedParams,
Expand All @@ -11,21 +15,14 @@
data class AuthFollowUpClickedParams(
val tabId: String,
val messageId: String,
val authFollowupType: String,
) {
companion object {
fun create(tabId: String, messageId: String, authType: AuthFollowupType): AuthFollowUpClickedParams =
AuthFollowUpClickedParams(tabId, messageId, authType.value)
}
}
val authFollowupType: AuthFollowupType,
)

enum class AuthFollowupType(val value: String) {
@JsonAdapter(EnumJsonValueAdapter::class)
enum class AuthFollowupType(@JsonValue val repr: String) {

Check warning on line 22 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/AuthFollowUpClicked.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "repr" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Property "repr" is never used
FULL_AUTH("full-auth"),
RE_AUTH("re-auth"),
MISSING_SCOPES("missing_scopes"),
USE_SUPPORTED_AUTH("use-supported-auth"),
;

override fun toString(): String =
name.lowercase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

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

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonValue
import com.google.gson.annotations.JsonAdapter
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.EnumJsonValueAdapter

data class ChatMessage(
val type: MessageType? = MessageType.ANSWER,
Expand Down Expand Up @@ -69,92 +71,51 @@
val total: Int? = null,
)

enum class IconType {
@JsonProperty("file")
FILE,

@JsonProperty("folder")
FOLDER,

@JsonProperty("code-block")
CODE_BLOCK,

@JsonProperty("list-add")
LIST_ADD,

@JsonProperty("magic")
MAGIC,

@JsonProperty("help")
HELP,

@JsonProperty("trash")
TRASH,

@JsonProperty("search")
SEARCH,

@JsonProperty("calendar")
CALENDAR,
@JsonAdapter(EnumJsonValueAdapter::class)
enum class IconType(@JsonValue val repr: String) {

Check warning on line 75 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "repr" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Property "repr" is never used
FILE("file"),
FOLDER("folder"),

Check warning on line 77 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "FOLDER" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Class "FOLDER" is never used
CODE_BLOCK("code-block"),
LIST_ADD("list-add"),

Check warning on line 79 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "LIST_ADD" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Class "LIST_ADD" is never used
MAGIC("magic"),

Check warning on line 80 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "MAGIC" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Class "MAGIC" is never used
HELP("help"),

Check warning on line 81 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "HELP" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Class "HELP" is never used
TRASH("trash"),

Check warning on line 82 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "TRASH" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Class "TRASH" is never used
SEARCH("search"),

Check warning on line 83 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "SEARCH" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Class "SEARCH" is never used
CALENDAR("calendar"),

Check warning on line 84 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Class "CALENDAR" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Class "CALENDAR" is never used
;

companion object {
private val stringToEnum: Map<String, IconType> = entries.associateBy { it.name.lowercase() }

fun fromString(value: String): IconType = stringToEnum[value] ?: throw IllegalArgumentException("Unknown IconType: $value")
}
}

enum class Status {
@JsonProperty("info")
INFO,

@JsonProperty("success")
SUCCESS,

@JsonProperty("warning")
WARNING,
@JsonAdapter(EnumJsonValueAdapter::class)
enum class Status(@JsonValue val repr: String) {

Check warning on line 90 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "repr" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Property "repr" is never used
INFO("info"),
SUCCESS("success"),
WARNING("warning"),
ERROR("error"),
;

@JsonProperty("error")
ERROR,
}

enum class ButtonStatus {
@JsonProperty("main")
MAIN,

@JsonProperty("primary")
PRIMARY,

@JsonProperty("clear")
CLEAR,

@JsonProperty("info")
INFO,

@JsonProperty("success")
SUCCESS,

@JsonProperty("warning")
WARNING,
@JsonAdapter(EnumJsonValueAdapter::class)
enum class ButtonStatus(@JsonValue val repr: String) {

Check warning on line 100 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "repr" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Property "repr" is never used
MAIN("main"),
PRIMARY("primary"),
CLEAR("clear"),
INFO("info"),
SUCCESS("success"),
WARNING("warning"),
ERROR("error"),
;

@JsonProperty("error")
ERROR,
}

enum class MessageType {
@JsonProperty("answer")
ANSWER,

@JsonProperty("prompt")
PROMPT,

@JsonProperty("system-prompt")
SYSTEM_PROMPT,

@JsonProperty("directive")
DIRECTIVE,

@JsonProperty("tool")
TOOL,
// https://github.com/aws/language-server-runtimes/blame/68319c975d29a8ba9b084c9fa780ebff75b286bb/types/chat.ts#L127
@JsonAdapter(EnumJsonValueAdapter::class)
enum class MessageType(@JsonValue val repr: String) {

Check warning on line 114 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/model/aws/chat/ChatMessage.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Property "repr" is never used

Check warning

Code scanning / QDJVMC

Unused symbol Warning

Property "repr" is never used
ANSWER("answer"),
PROMPT("prompt"),
SYSTEM_PROMPT("system-prompt"),
DIRECTIVE("directive"),
TOOL("tool"),
;
}

This file was deleted.

Loading
Loading