Skip to content

fix(amazonq): Fix Generate unit tests from right click context menu #5705

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
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -5,6 +5,7 @@

import com.intellij.openapi.project.Project
import software.aws.toolkits.jetbrains.services.amazonq.commands.MessageTypeRegistry
import software.aws.toolkits.jetbrains.services.amazonq.messages.MessageConnector

Check warning on line 8 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/apps/AmazonQAppInitContext.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.amazonq.messages.MessageListener
import software.aws.toolkits.jetbrains.services.amazonq.messages.MessagePublisher
import software.aws.toolkits.jetbrains.services.amazonq.webview.FqnWebviewAdapter
Expand All @@ -19,3 +20,7 @@
val messageTypeRegistry: MessageTypeRegistry,
val fqnWebviewAdapter: FqnWebviewAdapter,
)




Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ class AmazonQPanel(val project: Project, private val scope: CoroutineScope) : Di
}
}

fun getDefaultAppInitContext() : AmazonQAppInitContext {

return AmazonQAppInitContext(
project = project,
messagesFromAppToUi = MessageConnector(),
messagesFromUiToApp = MessageConnector(),
messageTypeRegistry = MessageTypeRegistry(),
fqnWebviewAdapter = FqnWebviewAdapter(jcefBrowser = browser.get().jcefBrowser, browserConnector),
)
}

override fun dispose() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.wm.ToolWindowManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import software.aws.toolkits.jetbrains.services.amazonq.onboarding.OnboardingPageInteraction
import software.aws.toolkits.jetbrains.services.amazonq.onboarding.OnboardingPageInteractionType
import software.aws.toolkits.jetbrains.services.amazonqCodeScan.runCodeScanMessage
import software.aws.toolkits.jetbrains.services.cwc.controller.TestCommandMessage

@Service(Service.Level.PROJECT)
class AmazonQToolWindow private constructor(
Expand Down Expand Up @@ -52,6 +54,14 @@
val window = getInstance(project)
window.chatPanel.sendMessageAppToUi(runCodeScanMessage, tabType = "codescan")
}

fun sendTestMessage(project: Project) {
runBlocking {
val a = getInstance(project).chatPanel.getDefaultAppInitContext()
val b = a.messagesFromAppToUi.publish(TestCommandMessage())

Check warning on line 61 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/AmazonQToolWindow.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused variable

Unused variable
}

}
}

override fun dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
import com.intellij.openapi.project.Project
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.runBlocking

Check warning on line 9 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/ActionRegistrar.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext

Check warning on line 10 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/ActionRegistrar.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.amazonq.commands.MessageTypeRegistry

Check warning on line 11 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/ActionRegistrar.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.AsyncChatUiListener

Check warning on line 12 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/ActionRegistrar.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.amazonq.messages.AmazonQMessage
import software.aws.toolkits.jetbrains.services.amazonq.messages.MessageConnector

Check warning on line 14 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/ActionRegistrar.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindow
import software.aws.toolkits.jetbrains.services.amazonq.webview.FqnWebviewAdapter

Check warning on line 16 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/ActionRegistrar.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import software.aws.toolkits.jetbrains.services.cwc.controller.TestCommandMessage

Check warning on line 17 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/ActionRegistrar.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive

// Register Editor Actions in the Editor Context Menu
class ActionRegistrar {
Expand All @@ -15,7 +23,14 @@
val flow = _messages.asSharedFlow()

fun reportMessageClick(command: EditorContextCommand, project: Project) {
_messages.tryEmit(ContextMenuActionMessage(command, project))
// language=JSON
AmazonQToolWindow.sendTestMessage(project)
//AsyncChatUiListener.notifyPartialMessageUpdate(a)
// _messages.tryEmit(ContextMenuActionMessage(command, project))
// runBlocking {
// MessageConnector().publish(messageToPublish)
// }

}

fun reportMessageClick(command: EditorContextCommand, issue: MutableMap<String, String>, project: Project) {
Expand All @@ -27,3 +42,10 @@
val instance = ActionRegistrar()
}
}
//fun getContext(project: Project) = AmazonQAppInitContext(
// project,
// MessageConnector(),
// MessageConnector(),
// MessageTypeRegistry(),
// FqnWebviewAdapter(project)
//)
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ import software.aws.toolkits.telemetry.CwsprChatCommandType
import java.util.UUID

data class TestCommandMessage(
val sender: String = "codetest",
val sender: String = "testChat",
val command: String = "test",
val type: String = "addAnswer",
val type: String = "chatMessage",
) : AmazonQMessage

class ChatController private constructor(
Expand Down
Loading