Skip to content

Commit be2a6e2

Browse files
committed
delete dummy popup and set nullable popup
1 parent 6d4e34f commit be2a6e2

File tree

6 files changed

+24
-26
lines changed

6 files changed

+24
-26
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/inlay/CodeWhispererInlayManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CodeWhispererInlayManager {
2222
clearInlays()
2323

2424
chunks.forEach { chunk ->
25-
createCodeWhispererInlays(editor, chunk.inlayOffset, chunk.text, states.popup)
25+
states.popup?.let { createCodeWhispererInlays(editor, chunk.inlayOffset, chunk.text, it) }
2626
}
2727
}
2828

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/model/CodeWhispererModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ data class InvocationContext(
216216
val requestContext: RequestContext,
217217
val responseContext: ResponseContext,
218218
val recommendationContext: RecommendationContext,
219-
val popup: JBPopup,
219+
val popup: JBPopup? = null,
220220
) : Disposable {
221221
override fun dispose() {}
222222
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ class CodeWhispererPopupManager {
141141
val startOffset = states.requestContext.caretPosition.offset
142142
val currOffset = states.requestContext.editor.caretModel.offset
143143
if (startOffset > currOffset) {
144-
cancelPopup(popup)
144+
popup?.let { cancelPopup(popup) }
145145
return
146146
}
147147

148148
// userInput + typeahead
149149
val prefix = states.requestContext.editor.document.charsSequence
150150
.substring(startOffset, currOffset)
151151
if (prefix.length < userInputOriginal.length) {
152-
cancelPopup(popup)
152+
popup?.let { cancelPopup(popup) }
153153
return
154154
} else {
155155
prefix.substring(userInputOriginal.length)
@@ -172,7 +172,7 @@ class CodeWhispererPopupManager {
172172
)
173173
if (selectedIndex == -1 || !isValidRecommendation(details[selectedIndex], userInput, typeaheadOriginal)) {
174174
LOG.debug { "None of the recommendation is valid at this point, cancelling the popup" }
175-
cancelPopup(popup)
175+
popup?.let { cancelPopup(popup) }
176176
return
177177
}
178178
val typeahead = resolveTypeahead(states, selectedIndex, typeaheadOriginal)
@@ -245,7 +245,7 @@ class CodeWhispererPopupManager {
245245
states.requestContext.latencyContext.getPerceivedLatency(states.requestContext.triggerTypeInfo.triggerType)
246246
}
247247
if (!isRecommendationAdded) {
248-
showPopup(states, sessionContext, states.popup, visible = sessionContext.isPopupShowing)
248+
states.popup?.let { showPopup(states, sessionContext, it, visible = sessionContext.isPopupShowing) }
249249
}
250250
}
251251

@@ -423,8 +423,8 @@ class CodeWhispererPopupManager {
423423

424424
private fun addPopupListener(states: InvocationContext) {
425425
val listener = CodeWhispererPopupListener(states)
426-
states.popup.addListener(listener)
427-
Disposer.register(states) { states.popup.removeListener(listener) }
426+
states.popup?.addListener(listener)
427+
Disposer.register(states) { states.popup?.removeListener(listener) }
428428
}
429429

430430
private fun addMessageSubscribers(states: InvocationContext) {
@@ -460,7 +460,7 @@ class CodeWhispererPopupManager {
460460
dontClosePopupAndRun {
461461
CodeWhispererEditorManager.getInstance().updateEditorWithRecommendation(states, sessionContext)
462462
}
463-
closePopup(states.popup)
463+
states.popup?.let { closePopup(it) }
464464
if (sessionContext.selectedIndex == 0) {
465465
CodeWhispererService.getInstance().promoteNextInvocationIfAvailable()
466466
}
@@ -512,7 +512,7 @@ class CodeWhispererPopupManager {
512512
val codewhispererSelectionListener: SelectionListener = object : SelectionListener {
513513
override fun selectionChanged(event: SelectionEvent) {
514514
if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW) {
515-
cancelPopup(states.popup)
515+
states.popup?.let { cancelPopup(it) }
516516
}
517517
super.selectionChanged(event)
518518
}
@@ -528,7 +528,7 @@ class CodeWhispererPopupManager {
528528
if (editor.caretModel.offset == event.offset) {
529529
changeStates(states, 0)
530530
} else if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW) {
531-
cancelPopup(states.popup)
531+
states.popup?.let { cancelPopup(it) }
532532
}
533533
}
534534
}
@@ -537,7 +537,7 @@ class CodeWhispererPopupManager {
537537
val codewhispererCaretListener: CaretListener = object : CaretListener {
538538
override fun caretPositionChanged(event: CaretEvent) {
539539
if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW) {
540-
cancelPopup(states.popup)
540+
states.popup?.let { cancelPopup(it) }
541541
}
542542
super.caretPositionChanged(event)
543543
}
@@ -550,11 +550,11 @@ class CodeWhispererPopupManager {
550550
val window = ComponentUtil.getWindow(editorComponent)
551551
val windowListener: ComponentListener = object : ComponentAdapter() {
552552
override fun componentMoved(event: ComponentEvent) {
553-
cancelPopup(states.popup)
553+
states.popup?.let { cancelPopup(it) }
554554
}
555555

556556
override fun componentShown(e: ComponentEvent?) {
557-
cancelPopup(states.popup)
557+
states.popup?.let { cancelPopup(it) }
558558
super.componentShown(e)
559559
}
560560
}
@@ -565,7 +565,7 @@ class CodeWhispererPopupManager {
565565
val suggestionHoverEnterListener: EditorMouseMotionListener = object : EditorMouseMotionListener {
566566
override fun mouseMoved(e: EditorMouseEvent) {
567567
if (e.inlay != null) {
568-
showPopup(states, sessionContext, states.popup, visible = true)
568+
states.popup?.let { showPopup(states, sessionContext, it, visible = true) }
569569
} else {
570570
bringSuggestionInlayToFront(editor, states.popup, sessionContext, opposite = true)
571571
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ class CodeWhispererUIChangeListener : CodeWhispererPopupStateChangeListener {
6161
},
6262
HighlighterTargetArea.EXACT_RANGE
6363
)
64-
Disposer.register(states.popup) {
65-
editor.markupModel.removeHighlighter(rangeHighlighter)
64+
states.popup?.let {
65+
Disposer.register(it) {
66+
editor.markupModel.removeHighlighter(rangeHighlighter)
67+
}
6668
}
6769
sessionContext.toBeRemovedHighlighter = rangeHighlighter
6870
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispe
1313

1414
class CodeWhispererPopupEscHandler(states: InvocationContext) : CodeWhispererEditorActionHandler(states) {
1515
override fun doExecute(editor: Editor, caret: Caret?, dataContext: DataContext?) {
16-
CodeWhispererPopupManager.getInstance().cancelPopup(states.popup)
16+
states.popup?.let { CodeWhispererPopupManager.getInstance().cancelPopup(it) }
1717
}
1818
}
1919

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import com.intellij.openapi.editor.Editor
1616
import com.intellij.openapi.editor.VisualPosition
1717
import com.intellij.openapi.project.Project
1818
import com.intellij.openapi.ui.popup.JBPopup
19-
import com.intellij.openapi.ui.popup.JBPopupFactory
2019
import com.intellij.openapi.util.Disposer
2120
import com.intellij.psi.PsiDocumentManager
2221
import com.intellij.psi.PsiFile
@@ -299,12 +298,9 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
299298
}
300299
}
301300
val nextRecommendationContext = RecommendationContext(detailContexts, "", "", newVisualPosition)
302-
val newPopup = withContext(EDT) {
303-
JBPopupFactory.getInstance().createMessage("Dummy popup")
304-
}
305301

306302
// send userDecision and trigger decision when next recommendation haven't been seen
307-
if (currStates.popup.isDisposed) {
303+
if (currStates.popup?.isDisposed == true) {
308304
CodeWhispererTelemetryService.getInstance().sendUserDecisionEventForAll(
309305
nextRequestContext,
310306
nextResponseContext,
@@ -313,7 +309,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
313309
false
314310
)
315311
} else {
316-
nextInvocationContext = InvocationContext(nextRequestContext, nextResponseContext, nextRecommendationContext, newPopup)
312+
nextInvocationContext = InvocationContext(nextRequestContext, nextResponseContext, nextRecommendationContext, null)
317313
}
318314
LOG.debug { "Prefetched next invocation stored in nextInvocationContext" }
319315
}
@@ -709,7 +705,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
709705
val updatedStates = states.copy(
710706
recommendationContext = recommendationContext.copy(details = details + newDetailContexts)
711707
)
712-
Disposer.register(states.popup, updatedStates)
708+
states.popup?.let { Disposer.register(it, updatedStates) }
713709
CodeWhispererPopupManager.getInstance().initPopupListener(updatedStates)
714710
return updatedStates
715711
}
@@ -744,7 +740,7 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable {
744740
cs.launch {
745741
val newPopup = CodeWhispererPopupManager.getInstance().initPopup()
746742
val updatedNextStates = nextStates.copy(popup = newPopup).also {
747-
addPopupChildDisposables(it.requestContext.project, it.requestContext.editor, it.popup)
743+
it.popup?.let { it1 -> addPopupChildDisposables(it.requestContext.project, it.requestContext.editor, it1) }
748744
Disposer.register(newPopup, it)
749745
}
750746
CodeWhispererPopupManager.getInstance().initPopupListener(updatedNextStates)

0 commit comments

Comments
 (0)