@@ -37,7 +37,6 @@ import com.intellij.ui.awt.RelativePoint
3737import com.intellij.ui.popup.AbstractPopup
3838import com.intellij.ui.popup.PopupFactoryImpl
3939import com.intellij.util.concurrency.annotations.RequiresEdt
40- import com.intellij.util.messages.Topic
4140import com.intellij.util.ui.UIUtil
4241import software.amazon.awssdk.services.codewhispererruntime.model.Import
4342import software.amazon.awssdk.services.codewhispererruntime.model.Reference
@@ -51,6 +50,8 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.model.DetailContex
5150import software.aws.toolkits.jetbrains.services.codewhisperer.model.InvocationContextNew
5251import software.aws.toolkits.jetbrains.services.codewhisperer.model.PreviewContext
5352import 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
5455import software.aws.toolkits.jetbrains.services.codewhisperer.popup.handlers.CodeWhispererEditorActionHandlerNew
5556import software.aws.toolkits.jetbrains.services.codewhisperer.popup.handlers.CodeWhispererPopupBackspaceHandlerNew
5657import 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}
0 commit comments