@@ -41,11 +41,9 @@ import com.intellij.ui.popup.AbstractPopup
4141import com.intellij.ui.popup.PopupFactoryImpl
4242import com.intellij.util.messages.Topic
4343import com.intellij.util.ui.UIUtil
44- import kotlinx.coroutines.sync.Semaphore
4544import software.amazon.awssdk.services.codewhispererruntime.model.Import
4645import software.amazon.awssdk.services.codewhispererruntime.model.Reference
4746import software.aws.toolkits.core.utils.debug
48- import software.aws.toolkits.core.utils.error
4947import software.aws.toolkits.core.utils.getLogger
5048import software.aws.toolkits.jetbrains.services.codewhisperer.editor.CodeWhispererEditorManager
5149import software.aws.toolkits.jetbrains.services.codewhisperer.layout.CodeWhispererLayoutConfig.addHorizontalGlue
@@ -88,8 +86,8 @@ import javax.swing.JLabel
8886class CodeWhispererPopupManager {
8987 val popupComponents = CodeWhispererPopupComponents ()
9088
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
9391 var sessionContext = SessionContext ()
9492 private set
9593
@@ -251,18 +249,11 @@ class CodeWhispererPopupManager {
251249
252250 // Don't want to block or throw any kinds of exceptions here if it can continue to provide suggestions
253251 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
266257 }
267258 }
268259
@@ -511,7 +502,7 @@ class CodeWhispererPopupManager {
511502 val editor = states.requestContext.editor
512503 val codewhispererSelectionListener: SelectionListener = object : SelectionListener {
513504 override fun selectionChanged (event : SelectionEvent ) {
514- if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW ) {
505+ if (! allowTypingDuringSuggestionPreview && ! allowIntelliSenseDuringSuggestionPreview ) {
515506 cancelPopup(states.popup)
516507 }
517508 super .selectionChanged(event)
@@ -527,7 +518,7 @@ class CodeWhispererPopupManager {
527518 if (! delete) return
528519 if (editor.caretModel.offset == event.offset) {
529520 changeStates(states, 0 )
530- } else if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW ) {
521+ } else if (! allowTypingDuringSuggestionPreview && ! allowIntelliSenseDuringSuggestionPreview ) {
531522 cancelPopup(states.popup)
532523 }
533524 }
@@ -536,7 +527,7 @@ class CodeWhispererPopupManager {
536527
537528 val codewhispererCaretListener: CaretListener = object : CaretListener {
538529 override fun caretPositionChanged (event : CaretEvent ) {
539- if (allowEditsDuringSuggestionPreview.availablePermits == MAX_EDIT_SOURCE_DURING_SUGGESTION_PREVIEW ) {
530+ if (! allowTypingDuringSuggestionPreview && ! allowIntelliSenseDuringSuggestionPreview ) {
540531 cancelPopup(states.popup)
541532 }
542533 super .caretPositionChanged(event)
0 commit comments