-
Notifications
You must be signed in to change notification settings - Fork 273
fix(amazonq): Support chat quick action commands #5700
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
Changes from 6 commits
a578559
989a939
77d9cab
88b28a9
017e925
92062ee
8146d97
466fe68
d2e651e
5313dad
bda4422
bcd66db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,20 @@ | ||
| // Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| @file:Suppress("BannedImports") | ||
| package software.aws.toolkits.jetbrains.services.cwc.commands | ||
|
|
||
| import com.intellij.openapi.project.Project | ||
| import kotlinx.coroutines.flow.MutableSharedFlow | ||
| import kotlinx.coroutines.flow.asSharedFlow | ||
| import kotlinx.coroutines.runBlocking | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.AsyncChatUiListener | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.FlareUiMessage | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GenericCommandParams | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.SendToPromptParams | ||
| import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.TriggerType | ||
| import software.aws.toolkits.jetbrains.services.amazonq.messages.AmazonQMessage | ||
| import software.aws.toolkits.jetbrains.services.cwc.editor.context.ActiveFileContextExtractor | ||
| import software.aws.toolkits.jetbrains.services.cwc.editor.context.ExtractionTriggerType | ||
|
|
||
| // Register Editor Actions in the Editor Context Menu | ||
| class ActionRegistrar { | ||
|
|
@@ -15,7 +23,26 @@ | |
| val flow = _messages.asSharedFlow() | ||
|
|
||
| fun reportMessageClick(command: EditorContextCommand, project: Project) { | ||
| _messages.tryEmit(ContextMenuActionMessage(command, project)) | ||
| if (command == EditorContextCommand.GenerateUnitTests) { | ||
| // pre-existing old chat code path | ||
| _messages.tryEmit(ContextMenuActionMessage(command, project)) | ||
| } else { | ||
| // new agentic chat route | ||
| runBlocking { | ||
|
||
| val contextExtractor = ActiveFileContextExtractor.create(fqnWebviewAdapter = null, project = project) | ||
| val fileContext = contextExtractor.extractContextForTrigger(ExtractionTriggerType.ContextMenu) | ||
| val codeSelection = "\n```\n${fileContext.focusAreaContext?.codeSelection?.trimIndent()?.trim()}\n```\n" | ||
| var uiMessage: FlareUiMessage? = null | ||
|
||
| if (command.verb != "sendToPrompt") { | ||
| val params = GenericCommandParams(selection = codeSelection, triggerType = TriggerType.CONTEXT_MENU, genericCommand = command.name) | ||
| uiMessage = FlareUiMessage(command = "genericCommand", params = params) | ||
| } else { | ||
| val params = SendToPromptParams(selection = codeSelection, triggerType = TriggerType.CONTEXT_MENU) | ||
| uiMessage = FlareUiMessage(command = "sendToPrompt", params = params) | ||
| } | ||
| AsyncChatUiListener.notifyPartialMessageUpdate(uiMessage) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun reportMessageClick(command: EditorContextCommand, issue: MutableMap<String, String>, project: Project) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // 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.aws.chat | ||
|
|
||
| // https://github.com/aws/language-server-runtimes/blob/main/chat-client-ui-types/src/uiContracts.ts#L27 | ||
| enum class TriggerType(val value: String) { | ||
leigaol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| HOTKEYS("hotkeys"), | ||
|
||
| CLICK("click"), | ||
|
||
| CONTEXT_MENU("contextMenu"), | ||
| } | ||
|
|
||
| data class GenericCommandParams( | ||
| val tabId: String? = null, | ||
| val selection: String, | ||
leigaol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val triggerType: TriggerType, | ||
| val genericCommand: String, | ||
| ) | ||
|
|
||
| // https://github.com/aws/language-server-runtimes/blob/b7c4718b9bd84e08e72b992da5d699549af9f115/chat-client-ui-types/src/uiContracts.ts#L67 | ||
| data class SendToPromptParams( | ||
leigaol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val selection: String, | ||
| val triggerType: TriggerType, | ||
| val prompt: ChatPrompt? = null, | ||
| val autoSubmit: Boolean? = null, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.