Skip to content

Commit 8993cca

Browse files
feat(amazonq): clean up and delete all sessions storage on profileChanged (#2004)
* add sessionClear * change listener to project level * change listener param * fx * ensure dev/test/review work * linter * hack * update endpoint * delete loh * revert transform change * cr * update session clear * leave stopModernize in codeModernizerManager --------- Co-authored-by: Will Lo <[email protected]> Co-authored-by: Will Lo <[email protected]>
1 parent 2a9f303 commit 8993cca

File tree

18 files changed

+133
-2
lines changed

18 files changed

+133
-2
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeScan/CodeScanChatApp.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQApp
2121
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
2222
import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthController
2323
import software.aws.toolkits.jetbrains.services.amazonq.messages.AmazonQMessage
24+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfile
25+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileSelectedListener
2426
import software.aws.toolkits.jetbrains.services.amazonqCodeScan.auth.isCodeScanAvailable
2527
import software.aws.toolkits.jetbrains.services.amazonqCodeScan.commands.CodeScanActionMessage
2628
import software.aws.toolkits.jetbrains.services.amazonqCodeScan.commands.CodeScanMessageListener
@@ -141,6 +143,15 @@ class CodeScanChatApp(private val scope: CoroutineScope) : AmazonQApp {
141143
}
142144
}
143145
)
146+
147+
context.project.messageBus.connect(this).subscribe(
148+
QRegionProfileSelectedListener.TOPIC,
149+
object : QRegionProfileSelectedListener {
150+
override fun onProfileSelected(project: Project, profile: QRegionProfile?) {
151+
chatSessionStorage.deleteAllSessions()
152+
}
153+
}
154+
)
144155
}
145156

146157
private fun getQTokenProvider(project: Project) = (

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeScan/storage/ChatSessionStorage.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ class ChatSessionStorage {
3030
fun changeAuthenticationNeededNotified(authNeededNotified: Boolean) {
3131
sessions.keys.forEach { sessions[it]?.authNeededNotified = authNeededNotified }
3232
}
33+
34+
fun deleteAllSessions() {
35+
sessions.clear()
36+
}
3337
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/CodeTestChatApp.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
package software.aws.toolkits.jetbrains.services.amazonqCodeTest
55

66
import com.intellij.openapi.application.ApplicationManager
7+
import com.intellij.openapi.project.Project
78
import kotlinx.coroutines.CoroutineScope
89
import kotlinx.coroutines.launch
910
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
1011
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManagerListener
1112
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQApp
1213
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
1314
import software.aws.toolkits.jetbrains.services.amazonq.messages.AmazonQMessage
15+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfile
16+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileSelectedListener
1417
import software.aws.toolkits.jetbrains.services.amazonqCodeScan.auth.isCodeScanAvailable
1518
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.auth.isCodeTestAvailable
1619
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.controller.CodeTestChatController
@@ -71,6 +74,15 @@ class CodeTestChatApp(private val scope: CoroutineScope) : AmazonQApp {
7174
}
7275
}
7376
)
77+
78+
context.project.messageBus.connect(this).subscribe(
79+
QRegionProfileSelectedListener.TOPIC,
80+
object : QRegionProfileSelectedListener {
81+
override fun onProfileSelected(project: Project, profile: QRegionProfile?) {
82+
chatSessionStorage.deleteAllSessions()
83+
}
84+
}
85+
)
7486
}
7587

7688
private suspend fun handleMessage(message: AmazonQMessage, inboundAppMessagesHandler: InboundAppMessagesHandler) {

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/CodeWhispererUTGChatManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ Please see the unit tests generated below. Click 'View Diff' to review the chang
541541
jobGroup = session.testGenerationJobGroupName,
542542
jobId = session.testGenerationJob,
543543
result = if (e.message == message("testgen.message.cancelled")) MetricResult.Cancelled else MetricResult.Failed,
544-
reason = (e as CodeTestException).code ?: "DefaultError",
545-
reasonDesc = if (e.message == message("testgen.message.cancelled")) "${e.code}: ${e.message}" else e.message,
544+
reason = (e as? CodeTestException)?.code ?: "DefaultError",
545+
reasonDesc = if (e.message == message("testgen.message.cancelled")) "${(e as? CodeTestException)?.code}: ${e.message}" else e.message,
546546
perfClientLatency = (Instant.now().toEpochMilli() - session.startTimeOfTestGeneration),
547547
isCodeBlockSelected = session.isCodeBlockSelected,
548548
artifactsUploadDuration = session.artifactUploadDuration,

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/storage/ChatSessionStorage.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ class ChatSessionStorage {
1717

1818
// Find all sessions that are currently waiting to be authenticated
1919
fun getAuthenticatingSessions(): List<Session> = this.sessions.values.filter { it.isAuthenticating }
20+
21+
fun deleteAllSessions() {
22+
sessions.clear()
23+
}
2024
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/DocApp.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
package software.aws.toolkits.jetbrains.services.amazonqDoc
55

66
import com.intellij.openapi.application.ApplicationManager
7+
import com.intellij.openapi.project.Project
78
import kotlinx.coroutines.launch
89
import software.aws.toolkits.jetbrains.core.coroutines.disposableCoroutineScope
910
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
1011
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManagerListener
1112
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQApp
1213
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
1314
import software.aws.toolkits.jetbrains.services.amazonq.messages.AmazonQMessage
15+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfile
16+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileSelectedListener
1417
import software.aws.toolkits.jetbrains.services.amazonqCodeScan.auth.isCodeScanAvailable
1518
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.auth.isCodeTestAvailable
1619
import software.aws.toolkits.jetbrains.services.amazonqDoc.auth.isDocAvailable
@@ -74,6 +77,15 @@ class DocApp : AmazonQApp {
7477
}
7578
}
7679
)
80+
81+
context.project.messageBus.connect(this).subscribe(
82+
QRegionProfileSelectedListener.TOPIC,
83+
object : QRegionProfileSelectedListener {
84+
override fun onProfileSelected(project: Project, profile: QRegionProfile?) {
85+
chatSessionStorage.deleteAllSessions()
86+
}
87+
}
88+
)
7789
}
7890

7991
private suspend fun handleMessage(message: AmazonQMessage, inboundAppMessagesHandler: InboundAppMessagesHandler) {

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/storage/ChatSessionStorage.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ class ChatSessionStorage {
2323

2424
// Find all sessions that are currently waiting to be authenticated
2525
fun getAuthenticatingSessions(): List<DocSession> = this.sessions.values.filter { it.isAuthenticating }
26+
27+
fun deleteAllSessions() {
28+
sessions.values.forEach { session ->
29+
session.sessionState.token?.cancel()
30+
}
31+
sessions.clear()
32+
}
2633
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/FeatureDevApp.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
package software.aws.toolkits.jetbrains.services.amazonqFeatureDev
55

66
import com.intellij.openapi.application.ApplicationManager
7+
import com.intellij.openapi.project.Project
78
import kotlinx.coroutines.launch
89
import software.aws.toolkits.jetbrains.core.coroutines.disposableCoroutineScope
910
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnection
1011
import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManagerListener
1112
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQApp
1213
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
1314
import software.aws.toolkits.jetbrains.services.amazonq.messages.AmazonQMessage
15+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfile
16+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileSelectedListener
1417
import software.aws.toolkits.jetbrains.services.amazonqCodeScan.auth.isCodeScanAvailable
1518
import software.aws.toolkits.jetbrains.services.amazonqCodeTest.auth.isCodeTestAvailable
1619
import software.aws.toolkits.jetbrains.services.amazonqDoc.auth.isDocAvailable
@@ -75,6 +78,15 @@ class FeatureDevApp : AmazonQApp {
7578
}
7679
}
7780
)
81+
82+
context.project.messageBus.connect(this).subscribe(
83+
QRegionProfileSelectedListener.TOPIC,
84+
object : QRegionProfileSelectedListener {
85+
override fun onProfileSelected(project: Project, profile: QRegionProfile?) {
86+
chatSessionStorage.deleteAllSessions()
87+
}
88+
}
89+
)
7890
}
7991

8092
private suspend fun handleMessage(message: AmazonQMessage, inboundAppMessagesHandler: InboundAppMessagesHandler) {

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/controller/FeatureDevController.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import software.aws.toolkits.jetbrains.core.coroutines.EDT
3232
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
3333
import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthController
3434
import software.aws.toolkits.jetbrains.services.amazonq.messages.MessagePublisher
35+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfile
36+
import software.aws.toolkits.jetbrains.services.amazonq.profile.QRegionProfileSelectedListener
3537
import software.aws.toolkits.jetbrains.services.amazonq.project.RepoSizeError
3638
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindowFactory
3739
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.CodeIterationLimitException
@@ -94,6 +96,17 @@ class FeatureDevController(
9496
private val authController: AuthController = AuthController(),
9597
) : InboundAppMessagesHandler {
9698

99+
init {
100+
context.project.messageBus.connect().subscribe(
101+
QRegionProfileSelectedListener.TOPIC,
102+
object : QRegionProfileSelectedListener {
103+
override fun onProfileSelected(project: Project, profile: QRegionProfile?) {
104+
chatSessionStorage.deleteAllSessions()
105+
}
106+
}
107+
)
108+
}
109+
97110
val messenger = context.messagesFromAppToUi
98111
val toolWindow = ToolWindowManager.getInstance(context.project).getToolWindow(AmazonQToolWindowFactory.WINDOW_ID)
99112

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/storage/ChatSessionStorage.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ class ChatSessionStorage {
2323

2424
// Find all sessions that are currently waiting to be authenticated
2525
fun getAuthenticatingSessions(): List<Session> = this.sessions.values.filter { it.isAuthenticating }
26+
27+
fun deleteAllSessions() {
28+
sessions.values.forEach { session ->
29+
session.sessionState.token?.cancel()
30+
}
31+
sessions.clear()
32+
}
2633
}

0 commit comments

Comments
 (0)