@@ -41,11 +41,9 @@ import com.intellij.ui.popup.AbstractPopup
41
41
import com.intellij.ui.popup.PopupFactoryImpl
42
42
import com.intellij.util.messages.Topic
43
43
import com.intellij.util.ui.UIUtil
44
- import kotlinx.coroutines.sync.Semaphore
45
44
import software.amazon.awssdk.services.codewhispererruntime.model.Import
46
45
import software.amazon.awssdk.services.codewhispererruntime.model.Reference
47
46
import software.aws.toolkits.core.utils.debug
48
- import software.aws.toolkits.core.utils.error
49
47
import software.aws.toolkits.core.utils.getLogger
50
48
import software.aws.toolkits.jetbrains.services.codewhisperer.editor.CodeWhispererEditorManager
51
49
import software.aws.toolkits.jetbrains.services.codewhisperer.layout.CodeWhispererLayoutConfig.addHorizontalGlue
@@ -88,8 +86,8 @@ import javax.swing.JLabel
88
86
class CodeWhispererPopupManager {
89
87
val popupComponents = CodeWhispererPopupComponents ()
90
88
91
- // Act like a semaphore: one increment only corresponds to one decrement
92
- var allowEditsDuringSuggestionPreview = Semaphore ( MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW )
89
+ var allowTypingDuringSuggestionPreview = false
90
+ var allowIntelliSenseDuringSuggestionPreview = false
93
91
var sessionContext = SessionContext ()
94
92
private set
95
93
@@ -251,18 +249,11 @@ class CodeWhispererPopupManager {
251
249
252
250
// Don't want to block or throw any kinds of exceptions here if it can continue to provide suggestions
253
251
fun dontClosePopupAndRun (runnable : () -> Unit ) {
254
- if (allowEditsDuringSuggestionPreview.tryAcquire()) {
255
- try {
256
- runnable()
257
- } finally {
258
- try {
259
- allowEditsDuringSuggestionPreview.release()
260
- } catch (e: Exception ) {
261
- LOG .error(e) { " Failed to release allowEditsDuringSuggestionPreview semaphore" }
262
- }
263
- }
264
- } else {
265
- LOG .error { " Failed to acquire allowEditsDuringSuggestionPreview semaphore" }
252
+ try {
253
+ allowTypingDuringSuggestionPreview = true
254
+ runnable()
255
+ } finally {
256
+ allowTypingDuringSuggestionPreview = false
266
257
}
267
258
}
268
259
@@ -511,7 +502,7 @@ class CodeWhispererPopupManager {
511
502
val editor = states.requestContext.editor
512
503
val codewhispererSelectionListener: SelectionListener = object : SelectionListener {
513
504
override fun selectionChanged (event : SelectionEvent ) {
514
- if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW ) {
505
+ if (! allowTypingDuringSuggestionPreview && ! allowIntelliSenseDuringSuggestionPreview ) {
515
506
cancelPopup(states.popup)
516
507
}
517
508
super .selectionChanged(event)
@@ -527,7 +518,7 @@ class CodeWhispererPopupManager {
527
518
if (! delete) return
528
519
if (editor.caretModel.offset == event.offset) {
529
520
changeStates(states, 0 )
530
- } else if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW ) {
521
+ } else if (! allowTypingDuringSuggestionPreview && ! allowIntelliSenseDuringSuggestionPreview ) {
531
522
cancelPopup(states.popup)
532
523
}
533
524
}
@@ -536,7 +527,7 @@ class CodeWhispererPopupManager {
536
527
537
528
val codewhispererCaretListener: CaretListener = object : CaretListener {
538
529
override fun caretPositionChanged (event : CaretEvent ) {
539
- if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW ) {
530
+ if (! allowTypingDuringSuggestionPreview && ! allowIntelliSenseDuringSuggestionPreview ) {
540
531
cancelPopup(states.popup)
541
532
}
542
533
super .caretPositionChanged(event)
0 commit comments