Skip to content

Commit

Permalink
revert the behavior of making IntelliSense and Q suggestions co-exist (
Browse files Browse the repository at this point in the history
…#5353)

* revert the behavior of making IntelliSense and Q suggestions co-exist

* change log

* Remove isQPrioritizedForTabAccept usage

* fix typing
  • Loading branch information
andrewyuq authored Feb 11, 2025
1 parent 9a60e50 commit a766f62
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Amazon Q: Reverting the behavior of making JetBrains suggestions(IntelliSense) and Q suggestions co-exist"
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</action>
<action id="codewhisperer.inline.force.accept"
class="software.aws.toolkits.jetbrains.services.codewhisperer.actions.CodeWhispererForceAcceptAction"
text="Force Accept the Current Inline Suggestion" description="Force accept the current inline suggestion">
text="Force Accept the Current Amazon Q Suggestion" description="Force accept the current Amazon Q suggestion">
<keyboard-shortcut keymap="Mac OS X" first-keystroke="alt TAB"/>
<keyboard-shortcut keymap="Mac OS X 10.5+" first-keystroke="alt TAB"/>
<keyboard-shortcut keymap="$default" first-keystroke="alt ENTER"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<out AnAction>, context: DataContext): MutableList<AnAction> {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<DetailContext>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,17 +97,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CodeWhispererConfigurableTest : CodeWhispererTestBase() {
)

val comments = panel.components.filterIsInstance<DslLabel>()
assertThat(comments.size).isEqualTo(10)
assertThat(comments.size).isEqualTo(8)

mockCodeWhispererEnabledStatus(false)
ApplicationManager.getApplication().messageBus.syncPublisher(ToolkitConnectionManagerListener.TOPIC)
Expand Down

0 comments on commit a766f62

Please sign in to comment.