Skip to content

Commit 12e7803

Browse files
authored
auto-trigger a/b (#4961)
* auto-trigger a/b * fix compile error * detekt fix * Keep one topic for all the listeners and changes around coroutine * test fix * detekt fix * change force accept to shift+tab and remove opt+ enter * keybinding change * change feature value to be string as service config has * test fix * Revert "test fix" This reverts commit b932c2c. * test fix
1 parent 91924e4 commit 12e7803

File tree

50 files changed

+3617
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3617
-110
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/resources/META-INF/plugin-codewhisperer.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
<applicationListeners>
66
<listener class="software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererUIChangeListener"
77
topic="software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererPopupStateChangeListener"/>
8+
<listener class="software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererUIChangeListenerNew"
9+
topic="software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererPopupStateChangeListener"/>
810
<listener class="software.aws.toolkits.jetbrains.services.codewhisperer.toolwindow.CodeWhispererCodeReferenceActionListener"
911
topic="software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererUserActionListener"/>
12+
<listener class="software.aws.toolkits.jetbrains.services.codewhisperer.toolwindow.CodeWhispererCodeReferenceActionListenerNew"
13+
topic="software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererUserActionListener"/>
1014
</applicationListeners>
1115

1216
<projectListeners>
@@ -81,9 +85,32 @@
8185
</group>
8286

8387
<action class="software.aws.toolkits.jetbrains.services.codewhisperer.actions.CodeWhispererRecommendationAction"
84-
text="Show Code Suggestions">
88+
text="Invoke Amazon Q Inline Suggestions">
8589
<keyboard-shortcut keymap="$default" first-keystroke="alt C"/>
8690
</action>
91+
<action id="codewhisperer.inline.navigate.previous"
92+
class="software.aws.toolkits.jetbrains.services.codewhisperer.actions.CodeWhispererNavigatePrevAction"
93+
text="Navigate to Previous Inline Suggestion" description="Navigate to previous inline suggestion">
94+
<keyboard-shortcut keymap="$default" first-keystroke="alt OPEN_BRACKET"/>
95+
</action>
96+
<action id="codewhisperer.inline.navigate.next"
97+
class="software.aws.toolkits.jetbrains.services.codewhisperer.actions.CodeWhispererNavigateNextAction"
98+
text="Navigate to Next Inline Suggestion" description="Navigate to next inline suggestion">
99+
<keyboard-shortcut keymap="$default" first-keystroke="alt CLOSE_BRACKET"/>
100+
</action>
101+
<action id="codewhisperer.inline.accept"
102+
class="software.aws.toolkits.jetbrains.services.codewhisperer.actions.CodeWhispererAcceptAction"
103+
text="Accept the Current Inline Suggestion" description="Accept the current inline suggestions">
104+
<keyboard-shortcut keymap="$default" first-keystroke="TAB"/>
105+
</action>
106+
<action id="codewhisperer.inline.force.accept"
107+
class="software.aws.toolkits.jetbrains.services.codewhisperer.actions.CodeWhispererForceAcceptAction"
108+
text="Force Accept the Current Inline Suggestion" description="Force accept the current inline suggestion">
109+
<keyboard-shortcut keymap="Mac OS X" first-keystroke="alt TAB"/>
110+
<keyboard-shortcut keymap="Mac OS X 10.5+" first-keystroke="alt TAB"/>
111+
<keyboard-shortcut keymap="$default" first-keystroke="alt ENTER"/>
112+
</action>
113+
87114
<group id="aws.toolkit.codewhisperer.toolbar.security">
88115
<action
89116
id="codewhisperer.toolbar.security.scan"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.codewhisperer.actions
5+
6+
import com.intellij.openapi.actionSystem.ActionUpdateThread
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.actionSystem.CommonDataKeys
10+
import com.intellij.openapi.application.ApplicationManager
11+
import com.intellij.openapi.project.DumbAware
12+
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererPopupManager
13+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatusNew
14+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererServiceNew
15+
import software.aws.toolkits.resources.message
16+
17+
open class CodeWhispererAcceptAction(title: String = message("codewhisperer.inline.accept")) : AnAction(title), DumbAware {
18+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
19+
20+
override fun update(e: AnActionEvent) {
21+
e.presentation.isEnabled = e.project != null && e.getData(CommonDataKeys.EDITOR) != null &&
22+
CodeWhispererInvocationStatusNew.getInstance().isDisplaySessionActive()
23+
}
24+
25+
override fun actionPerformed(e: AnActionEvent) {
26+
val sessionContext = e.project?.getUserData(CodeWhispererServiceNew.KEY_SESSION_CONTEXT) ?: return
27+
if (!CodeWhispererInvocationStatusNew.getInstance().isDisplaySessionActive()) return
28+
ApplicationManager.getApplication().messageBus.syncPublisher(
29+
CodeWhispererPopupManager.CODEWHISPERER_USER_ACTION_PERFORMED
30+
).beforeAccept(sessionContext)
31+
}
32+
}
33+
34+
// A same accept action but different key shortcut and different promoter logic
35+
class CodeWhispererForceAcceptAction(title: String = message("codewhisperer.inline.force.accept")) : CodeWhispererAcceptAction(title)

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/CodeWhispererActionPromoter.kt

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,46 @@
33

44
package software.aws.toolkits.jetbrains.services.codewhisperer.actions
55

6+
import com.intellij.codeInsight.lookup.impl.actions.ChooseItemAction
67
import com.intellij.openapi.actionSystem.ActionPromoter
78
import com.intellij.openapi.actionSystem.AnAction
89
import com.intellij.openapi.actionSystem.DataContext
910
import com.intellij.openapi.editor.actionSystem.EditorAction
1011
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.handlers.CodeWhispererPopupLeftArrowHandler
1112
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.handlers.CodeWhispererPopupRightArrowHandler
1213
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.handlers.CodeWhispererPopupTabHandler
14+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererFeatureConfigService
15+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatusNew
1316

1417
class CodeWhispererActionPromoter : ActionPromoter {
1518
override fun promote(actions: MutableList<out AnAction>, context: DataContext): MutableList<AnAction> {
19+
if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
20+
val results = actions.toMutableList()
21+
if (!CodeWhispererInvocationStatusNew.getInstance().isDisplaySessionActive()) return results
22+
23+
results.sortWith { a, b ->
24+
if (isCodeWhispererForceAction(a)) {
25+
return@sortWith -1
26+
} else if (isCodeWhispererForceAction(b)) {
27+
return@sortWith 1
28+
}
29+
30+
if (a is ChooseItemAction) {
31+
return@sortWith -1
32+
} else if (b is ChooseItemAction) {
33+
return@sortWith 1
34+
}
35+
36+
if (isCodeWhispererAcceptAction(a)) {
37+
return@sortWith -1
38+
} else if (isCodeWhispererAcceptAction(b)) {
39+
return@sortWith 1
40+
}
41+
42+
0
43+
}
44+
return results
45+
}
1646
val results = actions.toMutableList()
1747
results.sortWith { a, b ->
1848
if (isCodeWhispererPopupAction(a)) {
@@ -27,14 +57,28 @@ class CodeWhispererActionPromoter : ActionPromoter {
2757
}
2858

2959
private fun isCodeWhispererAcceptAction(action: AnAction): Boolean =
30-
action is EditorAction && action.handler is CodeWhispererPopupTabHandler
60+
if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
61+
action is CodeWhispererAcceptAction
62+
} else {
63+
action is EditorAction && action.handler is CodeWhispererPopupTabHandler
64+
}
65+
66+
private fun isCodeWhispererForceAcceptAction(action: AnAction): Boolean =
67+
action is CodeWhispererForceAcceptAction
3168

3269
private fun isCodeWhispererNavigateAction(action: AnAction): Boolean =
33-
action is EditorAction && (
34-
action.handler is CodeWhispererPopupRightArrowHandler ||
35-
action.handler is CodeWhispererPopupLeftArrowHandler
36-
)
70+
if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
71+
action is CodeWhispererNavigateNextAction || action is CodeWhispererNavigatePrevAction
72+
} else {
73+
action is EditorAction && (
74+
action.handler is CodeWhispererPopupRightArrowHandler ||
75+
action.handler is CodeWhispererPopupLeftArrowHandler
76+
)
77+
}
3778

3879
private fun isCodeWhispererPopupAction(action: AnAction): Boolean =
3980
isCodeWhispererAcceptAction(action) || isCodeWhispererNavigateAction(action)
81+
82+
private fun isCodeWhispererForceAction(action: AnAction): Boolean =
83+
isCodeWhispererForceAcceptAction(action) || isCodeWhispererNavigateAction(action)
4084
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.codewhisperer.actions
5+
6+
import com.intellij.openapi.actionSystem.ActionUpdateThread
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.actionSystem.CommonDataKeys
10+
import com.intellij.openapi.application.ApplicationManager
11+
import com.intellij.openapi.project.DumbAware
12+
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererPopupManager
13+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatusNew
14+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererServiceNew
15+
import software.aws.toolkits.resources.message
16+
17+
class CodeWhispererNavigateNextAction : AnAction(message("codewhisperer.inline.navigate.next")), DumbAware {
18+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
19+
20+
override fun update(e: AnActionEvent) {
21+
e.presentation.isEnabled = e.project != null &&
22+
e.getData(CommonDataKeys.EDITOR) != null &&
23+
CodeWhispererInvocationStatusNew.getInstance().isDisplaySessionActive()
24+
}
25+
26+
override fun actionPerformed(e: AnActionEvent) {
27+
val sessionContext = e.project?.getUserData(CodeWhispererServiceNew.KEY_SESSION_CONTEXT) ?: return
28+
if (!CodeWhispererInvocationStatusNew.getInstance().isDisplaySessionActive()) return
29+
ApplicationManager.getApplication().messageBus.syncPublisher(
30+
CodeWhispererPopupManager.CODEWHISPERER_USER_ACTION_PERFORMED
31+
).navigateNext(sessionContext)
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.services.codewhisperer.actions
5+
6+
import com.intellij.openapi.actionSystem.ActionUpdateThread
7+
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.actionSystem.AnActionEvent
9+
import com.intellij.openapi.actionSystem.CommonDataKeys
10+
import com.intellij.openapi.application.ApplicationManager
11+
import com.intellij.openapi.project.DumbAware
12+
import software.aws.toolkits.jetbrains.services.codewhisperer.popup.CodeWhispererPopupManager
13+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererInvocationStatusNew
14+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererServiceNew
15+
import software.aws.toolkits.resources.message
16+
17+
class CodeWhispererNavigatePrevAction : AnAction(message("codewhisperer.inline.navigate.previous")), DumbAware {
18+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
19+
20+
override fun update(e: AnActionEvent) {
21+
e.presentation.isEnabled = e.project != null &&
22+
e.getData(CommonDataKeys.EDITOR) != null &&
23+
CodeWhispererInvocationStatusNew.getInstance().isDisplaySessionActive()
24+
}
25+
26+
override fun actionPerformed(e: AnActionEvent) {
27+
val sessionContext = e.project?.getUserData(CodeWhispererServiceNew.KEY_SESSION_CONTEXT) ?: return
28+
if (!CodeWhispererInvocationStatusNew.getInstance().isDisplaySessionActive()) return
29+
ApplicationManager.getApplication().messageBus.syncPublisher(
30+
CodeWhispererPopupManager.CODEWHISPERER_USER_ACTION_PERFORMED
31+
).navigatePrevious(sessionContext)
32+
}
33+
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/CodeWhispererRecommendationAction.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import kotlinx.coroutines.Job
1313
import software.aws.toolkits.jetbrains.services.codewhisperer.model.LatencyContext
1414
import software.aws.toolkits.jetbrains.services.codewhisperer.model.TriggerTypeInfo
1515
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererAutomatedTriggerType
16+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererFeatureConfigService
1617
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererService
18+
import software.aws.toolkits.jetbrains.services.codewhisperer.service.CodeWhispererServiceNew
1719
import software.aws.toolkits.resources.message
1820
import software.aws.toolkits.telemetry.CodewhispererTriggerType
1921
import java.util.concurrent.atomic.AtomicReference
@@ -30,12 +32,23 @@ class CodeWhispererRecommendationAction : AnAction(message("codewhisperer.trigge
3032
latencyContext.codewhispererPreprocessingStart = System.nanoTime()
3133
latencyContext.codewhispererEndToEndStart = System.nanoTime()
3234
val editor = e.getRequiredData(CommonDataKeys.EDITOR)
33-
if (!CodeWhispererService.getInstance().canDoInvocation(editor, CodewhispererTriggerType.OnDemand)) {
35+
if (!(
36+
if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
37+
CodeWhispererServiceNew.getInstance().canDoInvocation(editor, CodewhispererTriggerType.OnDemand)
38+
} else {
39+
CodeWhispererService.getInstance().canDoInvocation(editor, CodewhispererTriggerType.OnDemand)
40+
}
41+
)
42+
) {
3443
return
3544
}
3645

3746
val triggerType = TriggerTypeInfo(CodewhispererTriggerType.OnDemand, CodeWhispererAutomatedTriggerType.Unknown())
38-
val job = CodeWhispererService.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
47+
val job = if (CodeWhispererFeatureConfigService.getInstance().getNewAutoTriggerUX()) {
48+
CodeWhispererServiceNew.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
49+
} else {
50+
CodeWhispererService.getInstance().showRecommendationsInPopup(editor, triggerType, latencyContext)
51+
}
3952

4053
e.getData(CommonDataKeys.EDITOR)?.getUserData(ACTION_JOB_KEY)?.set(job)
4154
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/actions/ConnectWithAwsToContinueActionWarn.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)