Skip to content

Commit d994940

Browse files
committed
Keep one topic for all the listeners and changes around coroutine
1 parent cc11b69 commit d994940

File tree

3 files changed

+218
-238
lines changed

3 files changed

+218
-238
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManagerNew.kt

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import com.intellij.ui.awt.RelativePoint
3737
import com.intellij.ui.popup.AbstractPopup
3838
import com.intellij.ui.popup.PopupFactoryImpl
3939
import com.intellij.util.concurrency.annotations.RequiresEdt
40-
import com.intellij.util.messages.Topic
4140
import com.intellij.util.ui.UIUtil
4241
import software.amazon.awssdk.services.codewhispererruntime.model.Import
4342
import software.amazon.awssdk.services.codewhispererruntime.model.Reference
@@ -51,6 +50,8 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.model.DetailContex
5150
import software.aws.toolkits.jetbrains.services.codewhisperer.model.InvocationContextNew
5251
import software.aws.toolkits.jetbrains.services.codewhisperer.model.PreviewContext
5352
import software.aws.toolkits.jetbrains.services.codewhisperer.model.SessionContextNew
53+
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererPopupManager.Companion.CODEWHISPERER_POPUP_STATE_CHANGED
54+
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererPopupManager.Companion.CODEWHISPERER_USER_ACTION_PERFORMED
5455
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.handlers.CodeWhispererEditorActionHandlerNew
5556
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.handlers.CodeWhispererPopupBackspaceHandlerNew
5657
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.handlers.CodeWhispererPopupEnterHandlerNew
@@ -134,8 +135,8 @@ class CodeWhispererPopupManagerNew {
134135
typeaheadChange: String,
135136
typeaheadAdded: Boolean,
136137
) {
137-
updateTypeahead(typeaheadChange, typeaheadAdded)
138-
updateSessionSelectedIndex(sessionContext)
138+
if (!updateTypeahead(typeaheadChange, typeaheadAdded)) return
139+
if (!updateSessionSelectedIndex(sessionContext)) return
139140
sessionContext.isFirstTimeShowingPopup = false
140141

141142
ApplicationManager.getApplication().messageBus.syncPublisher(CODEWHISPERER_POPUP_STATE_CHANGED).stateChanged(
@@ -152,7 +153,7 @@ class CodeWhispererPopupManagerNew {
152153
return
153154
}
154155

155-
updateSessionSelectedIndex(sessionContext)
156+
if (!updateSessionSelectedIndex(sessionContext)) return
156157
if (sessionContext.popupOffset == -1) {
157158
sessionContext.popupOffset = sessionContext.editor.caretModel.offset
158159
}
@@ -162,7 +163,7 @@ class CodeWhispererPopupManagerNew {
162163
)
163164
}
164165

165-
private fun updateTypeahead(typeaheadChange: String, typeaheadAdded: Boolean) {
166+
private fun updateTypeahead(typeaheadChange: String, typeaheadAdded: Boolean): Boolean {
166167
val recommendations = CodeWhispererServiceNew.getInstance().getAllPaginationSessions().values.filterNotNull()
167168
recommendations.forEach {
168169
val newTypeahead =
@@ -172,7 +173,7 @@ class CodeWhispererPopupManagerNew {
172173
if (typeaheadChange.length > it.recommendationContext.typeahead.length) {
173174
LOG.debug { "Typeahead change is longer than the current typeahead, exiting the session" }
174175
CodeWhispererServiceNew.getInstance().disposeDisplaySession(false)
175-
return
176+
return false
176177
}
177178
it.recommendationContext.typeahead.substring(
178179
0,
@@ -181,17 +182,19 @@ class CodeWhispererPopupManagerNew {
181182
}
182183
it.recommendationContext.typeahead = newTypeahead
183184
}
185+
return true
184186
}
185187

186-
private fun updateSessionSelectedIndex(sessionContext: SessionContextNew) {
188+
private fun updateSessionSelectedIndex(sessionContext: SessionContextNew): Boolean {
187189
val selectedIndex = findNewSelectedIndex(false, sessionContext.selectedIndex)
188190
if (selectedIndex == -1) {
189191
LOG.debug { "None of the recommendation is valid at this point, cancelling the popup" }
190192
CodeWhispererServiceNew.getInstance().disposeDisplaySession(false)
191-
return
193+
return false
192194
}
193195

194196
sessionContext.selectedIndex = selectedIndex
197+
return true
195198
}
196199

197200
fun updatePopupPanel(sessionContext: SessionContextNew?) {
@@ -621,13 +624,5 @@ class CodeWhispererPopupManagerNew {
621624
companion object {
622625
private val LOG = getLogger<CodeWhispererPopupManagerNew>()
623626
fun getInstance(): CodeWhispererPopupManagerNew = service()
624-
val CODEWHISPERER_POPUP_STATE_CHANGED: Topic<CodeWhispererPopupStateChangeListener> = Topic.create(
625-
"CodeWhisperer popup state changed",
626-
CodeWhispererPopupStateChangeListener::class.java
627-
)
628-
val CODEWHISPERER_USER_ACTION_PERFORMED: Topic<CodeWhispererUserActionListener> = Topic.create(
629-
"CodeWhisperer user action performed",
630-
CodeWhispererUserActionListener::class.java
631-
)
632627
}
633628
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererInvocationStatusNew.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.service
66
import com.intellij.openapi.application.ApplicationManager
77
import com.intellij.openapi.components.Service
88
import com.intellij.openapi.components.service
9-
import com.intellij.util.messages.Topic
109
import software.aws.toolkits.core.utils.debug
1110
import software.aws.toolkits.core.utils.getLogger
11+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatus.Companion.CODEWHISPERER_INVOCATION_STATE_CHANGED
1212
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants
1313
import java.time.Duration
1414
import java.time.Instant
@@ -78,9 +78,5 @@ class CodeWhispererInvocationStatusNew {
7878
companion object {
7979
private val LOG = getLogger<CodeWhispererInvocationStatusNew>()
8080
fun getInstance(): CodeWhispererInvocationStatusNew = service()
81-
val CODEWHISPERER_INVOCATION_STATE_CHANGED: Topic<CodeWhispererInvocationStateChangeListener> = Topic.create(
82-
"CodeWhisperer popup state changed",
83-
CodeWhispererInvocationStateChangeListener::class.java
84-
)
8581
}
8682
}

0 commit comments

Comments
 (0)