From da1d59423ab36d9a06b8251f0ece9ee7b1ffc7f0 Mon Sep 17 00:00:00 2001 From: Andrew Yu Date: Mon, 10 Feb 2025 15:14:25 -0800 Subject: [PATCH 1/5] revert the behavior of making IntelliSense and Q suggestions co-exist --- .../resources/META-INF/plugin-codewhisperer.xml | 2 +- .../popup/CodeWhispererPopupManager.kt | 5 +++++ .../codewhisperer/service/CodeWhispererService.kt | 13 +++++++++++++ .../settings/CodeWhispererConfigurable.kt | 11 ----------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/resources/META-INF/plugin-codewhisperer.xml b/plugins/amazonq/codewhisperer/jetbrains-community/resources/META-INF/plugin-codewhisperer.xml index d0594e1d4cf..7b9bb7b9eca 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/resources/META-INF/plugin-codewhisperer.xml +++ b/plugins/amazonq/codewhisperer/jetbrains-community/resources/META-INF/plugin-codewhisperer.xml @@ -106,7 +106,7 @@ + text="Force Accept the Current Amazon Q Suggestion" description="Force accept the current Amazon Q suggestion"> diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManager.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManager.kt index fed6542c551..245f9cdc453 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManager.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/popup/CodeWhispererPopupManager.kt @@ -3,6 +3,7 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.popup +import com.intellij.codeInsight.hint.ParameterInfoController import com.intellij.codeInsight.lookup.LookupManager import com.intellij.codeInsight.lookup.LookupManagerListener import com.intellij.idea.AppMode @@ -640,6 +641,10 @@ class CodeWhispererPopupManager { } } + fun hasConflictingPopups(editor: Editor): Boolean = + ParameterInfoController.existsWithVisibleHintForEditor(editor, true) || + LookupManager.getActiveLookup(editor) != null + private fun findNewSelectedIndex( isReverse: Boolean, detailContexts: List, diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt index 1b370cb0dbb..0773910bb03 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/service/CodeWhispererService.kt @@ -660,6 +660,12 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable { val recommendations = response.completions() val visualPosition = requestContext.editor.caretModel.visualPosition + if (CodeWhispererPopupManager.getInstance().hasConflictingPopups(requestContext.editor)) { + LOG.debug { "Detect conflicting popup window with CodeWhisperer popup, not showing CodeWhisperer popup" } + sendDiscardedUserDecisionEventForAll(requestContext, responseContext, recommendations) + return null + } + if (caretMovement == CaretMovement.MOVE_BACKWARD) { LOG.debug { "Caret moved backward, discarding all of the recommendations. Request ID: $requestId" } sendDiscardedUserDecisionEventForAll(requestContext, responseContext, recommendations) @@ -851,6 +857,8 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable { } private fun addPopupChildDisposables(project: Project, editor: Editor, popup: JBPopup) { + codeInsightSettingsFacade.disableCodeInsightUntil(popup) + Disposer.register(popup) { CodeWhispererPopupManager.getInstance().reset() } @@ -906,6 +914,11 @@ class CodeWhispererService(private val cs: CoroutineScope) : Disposable { return false } + if (CodeWhispererPopupManager.getInstance().hasConflictingPopups(editor)) { + LOG.debug { "Find other active popup windows before triggering CodeWhisperer, not invoking service" } + return false + } + if (CodeWhispererInvocationStatus.getInstance().isDisplaySessionActive()) { LOG.debug { "Find an existing CodeWhisperer popup window before triggering CodeWhisperer, not invoking service" } return false diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt index f26ffcea918..387626b14aa 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt @@ -98,17 +98,6 @@ class CodeWhispererConfigurable(private val project: Project) : }.comment(message("aws.settings.codewhisperer.automatic_import_adder.tooltip")) } - row { - text(message("codewhisperer.inline.settings.tab_priority.prefix")) - val amazonq = message("codewhisperer.inline.settings.tab_priority.choice.amazonq") - val jetbrains = message("codewhisperer.inline.settings.tab_priority.choice.jetbrains") - comboBox(listOf(amazonq, jetbrains)).bindItem( - { if (CodeWhispererSettings.getInstance().isQPrioritizedForTabAccept()) amazonq else jetbrains }, - { CodeWhispererSettings.getInstance().setQPrioritizedForTabAccept(it == amazonq) } - ) - text(message("codewhisperer.inline.settings.tab_priority.suffix")) - } - row { link("Configure inline suggestion keybindings") { e -> // TODO: user needs feedback if these are null From d50954b2bca0ea78925bd7d8cde9f08b3a6736be Mon Sep 17 00:00:00 2001 From: Andrew Yu Date: Mon, 10 Feb 2025 15:25:25 -0800 Subject: [PATCH 2/5] change log --- .../bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .changes/next-release/bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json diff --git a/.changes/next-release/bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json b/.changes/next-release/bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json new file mode 100644 index 00000000000..f1e26201096 --- /dev/null +++ b/.changes/next-release/bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Amazon Q: Reverting the behavior of making Jetbrains suggestions(IntelliSense) and Q suggestions co-exist" +} \ No newline at end of file From 14965560903e8e9e223f832f52674fdee747a020 Mon Sep 17 00:00:00 2001 From: Andrew Yu Date: Mon, 10 Feb 2025 15:29:43 -0800 Subject: [PATCH 3/5] Remove isQPrioritizedForTabAccept usage --- .../actions/CodeWhispererActionPromoter.kt | 30 +++---------------- .../settings/CodeWhispererConfigurable.kt | 1 - 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/CodeWhispererActionPromoter.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/CodeWhispererActionPromoter.kt index cb256c574b2..1e165f67f14 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/CodeWhispererActionPromoter.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/CodeWhispererActionPromoter.kt @@ -3,13 +3,11 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.actions -import com.intellij.codeInsight.lookup.impl.actions.ChooseItemAction import com.intellij.openapi.actionSystem.ActionPromoter import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.DataContext import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatus import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatusNew -import software.aws.toolkits.jetbrains.settings.CodeWhispererSettings class CodeWhispererActionPromoter : ActionPromoter { override fun promote(actions: MutableList, context: DataContext): MutableList { @@ -27,30 +25,10 @@ class CodeWhispererActionPromoter : ActionPromoter { return@sortWith 1 } - if (CodeWhispererSettings.getInstance().isQPrioritizedForTabAccept()) { - if (isCodeWhispererAcceptAction(a)) { - return@sortWith -1 - } else if (isCodeWhispererAcceptAction(b)) { - return@sortWith 1 - } - - if (a is ChooseItemAction) { - return@sortWith -1 - } else if (b is ChooseItemAction) { - return@sortWith 1 - } - } else { - if (a is ChooseItemAction) { - return@sortWith -1 - } else if (b is ChooseItemAction) { - return@sortWith 1 - } - - if (isCodeWhispererAcceptAction(a)) { - return@sortWith -1 - } else if (isCodeWhispererAcceptAction(b)) { - return@sortWith 1 - } + if (isCodeWhispererAcceptAction(a)) { + return@sortWith -1 + } else if (isCodeWhispererAcceptAction(b)) { + return@sortWith 1 } 0 diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt index 387626b14aa..94bcc93f5ca 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt @@ -13,7 +13,6 @@ import com.intellij.openapi.project.Project import com.intellij.ui.components.ActionLink import com.intellij.ui.components.fields.ExpandableTextField import com.intellij.ui.dsl.builder.bindIntText -import com.intellij.ui.dsl.builder.bindItem import com.intellij.ui.dsl.builder.bindSelected import com.intellij.ui.dsl.builder.bindText import com.intellij.ui.dsl.builder.panel From 1f92529fea3f6c5bb10195b96671ceceadf67324 Mon Sep 17 00:00:00 2001 From: Andrew Yu Date: Mon, 10 Feb 2025 15:36:01 -0800 Subject: [PATCH 4/5] fix typing --- .../bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/next-release/bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json b/.changes/next-release/bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json index f1e26201096..16dc9c7ec02 100644 --- a/.changes/next-release/bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json +++ b/.changes/next-release/bugfix-ed2a36a4-392d-4401-b51b-59f83ebeb8e6.json @@ -1,4 +1,4 @@ { "type" : "bugfix", - "description" : "Amazon Q: Reverting the behavior of making Jetbrains suggestions(IntelliSense) and Q suggestions co-exist" + "description" : "Amazon Q: Reverting the behavior of making JetBrains suggestions(IntelliSense) and Q suggestions co-exist" } \ No newline at end of file From d8414f17986accedb6bab6d353403400e4c13b44 Mon Sep 17 00:00:00 2001 From: Andrew Yu Date: Mon, 10 Feb 2025 16:07:50 -0800 Subject: [PATCH 5/5] fix test --- .../services/codewhisperer/CodeWhispererConfigurableTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererConfigurableTest.kt b/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererConfigurableTest.kt index 1436f2423f5..5224284b42a 100644 --- a/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererConfigurableTest.kt +++ b/plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererConfigurableTest.kt @@ -49,7 +49,7 @@ class CodeWhispererConfigurableTest : CodeWhispererTestBase() { ) val comments = panel.components.filterIsInstance() - assertThat(comments.size).isEqualTo(10) + assertThat(comments.size).isEqualTo(8) mockCodeWhispererEnabledStatus(false) ApplicationManager.getApplication().messageBus.syncPublisher(ToolkitConnectionManagerListener.TOPIC)