Skip to content

Commit 2ca4e5e

Browse files
committed
feat(amazonq): new auto trigger UX feature config changes
1. also removed idleTrigger type as it's not being used anywhere
1 parent 9fd91dd commit 2ca4e5e

File tree

3 files changed

+14
-64
lines changed

3 files changed

+14
-64
lines changed

packages/amazonq/test/unit/codewhisperer/service/keyStrokeHandler.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
DocumentChangedSource,
1919
KeyStrokeHandler,
2020
DefaultDocumentChangedType,
21-
RecommendationService,
2221
ClassifierTrigger,
2322
isInlineCompletionEnabled,
2423
RecommendationHandler,
@@ -37,11 +36,9 @@ describe('keyStrokeHandler', function () {
3736
})
3837
describe('processKeyStroke', async function () {
3938
let invokeSpy: sinon.SinonStub
40-
let startTimerSpy: sinon.SinonStub
4139
let mockClient: codewhispererSdkClient.DefaultCodeWhispererClient
4240
beforeEach(async function () {
4341
invokeSpy = sinon.stub(KeyStrokeHandler.instance, 'invokeAutomatedTrigger')
44-
startTimerSpy = sinon.stub(KeyStrokeHandler.instance, 'startIdleTimeTriggerTimer')
4542
sinon.spy(RecommendationHandler.instance, 'getRecommendations')
4643
mockClient = new codewhispererSdkClient.DefaultCodeWhispererClient()
4744
await resetCodeWhispererGlobalVariables()
@@ -68,7 +65,6 @@ describe('keyStrokeHandler', function () {
6865
const keyStrokeHandler = new KeyStrokeHandler()
6966
await keyStrokeHandler.processKeyStroke(mockEvent, mockEditor, mockClient, cfg)
7067
assert.ok(!invokeSpy.called)
71-
assert.ok(!startTimerSpy.called)
7268
})
7369

7470
it('Should not call invokeAutomatedTrigger when changed text across multiple lines', async function () {
@@ -185,15 +181,6 @@ describe('keyStrokeHandler', function () {
185181
})
186182
})
187183

188-
describe('shouldTriggerIdleTime', function () {
189-
it('should return false when inline is enabled and inline completion is in progress ', function () {
190-
const keyStrokeHandler = new KeyStrokeHandler()
191-
sinon.stub(RecommendationService.instance, 'isRunning').get(() => true)
192-
const result = keyStrokeHandler.shouldTriggerIdleTime()
193-
assert.strictEqual(result, !isInlineCompletionEnabled())
194-
})
195-
})
196-
197184
describe('test checkChangeSource', function () {
198185
const tabStr = ' '.repeat(EditorContext.getTabSize())
199186

packages/core/src/codewhisperer/service/keyStrokeHandler.ts

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55

66
import * as vscode from 'vscode'
77
import { DefaultCodeWhispererClient } from '../client/codewhisperer'
8-
import * as CodeWhispererConstants from '../models/constants'
98
import { ConfigurationEntry } from '../models/model'
109
import { getLogger } from '../../shared/logger'
1110
import { isCloud9 } from '../../shared/extensionUtilities'
12-
import { RecommendationHandler } from './recommendationHandler'
1311
import { CodewhispererAutomatedTriggerType } from '../../shared/telemetry/telemetry'
1412
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
15-
import { isInlineCompletionEnabled } from '../util/commonUtil'
1613
import { ClassifierTrigger } from './classifierTrigger'
1714
import { extractContextForCodeWhisperer } from '../util/editorContext'
1815
import { RecommendationService } from './recommendationService'
@@ -25,12 +22,6 @@ export class KeyStrokeHandler {
2522
* Special character which automated triggers codewhisperer
2623
*/
2724
public specialChar: string
28-
/**
29-
* Key stroke count for automated trigger
30-
*/
31-
32-
private idleTriggerTimer?: NodeJS.Timer
33-
3425
public lastInvocationTime?: number
3526

3627
constructor() {
@@ -43,48 +34,6 @@ export class KeyStrokeHandler {
4334
return (this.#instance ??= new this())
4435
}
4536

46-
public startIdleTimeTriggerTimer(
47-
event: vscode.TextDocumentChangeEvent,
48-
editor: vscode.TextEditor,
49-
client: DefaultCodeWhispererClient,
50-
config: ConfigurationEntry
51-
) {
52-
if (this.idleTriggerTimer) {
53-
clearInterval(this.idleTriggerTimer)
54-
this.idleTriggerTimer = undefined
55-
}
56-
if (!this.shouldTriggerIdleTime()) {
57-
return
58-
}
59-
this.idleTriggerTimer = setInterval(() => {
60-
const duration = (performance.now() - RecommendationHandler.instance.lastInvocationTime) / 1000
61-
if (duration < CodeWhispererConstants.invocationTimeIntervalThreshold) {
62-
return
63-
}
64-
65-
this.invokeAutomatedTrigger('IdleTime', editor, client, config, event)
66-
.catch((e) => {
67-
getLogger().error('invokeAutomatedTrigger failed: %s', (e as Error).message)
68-
})
69-
.finally(() => {
70-
if (this.idleTriggerTimer) {
71-
clearInterval(this.idleTriggerTimer)
72-
this.idleTriggerTimer = undefined
73-
}
74-
})
75-
}, CodeWhispererConstants.idleTimerPollPeriod)
76-
}
77-
78-
public shouldTriggerIdleTime(): boolean {
79-
if (isCloud9() && RecommendationService.instance.isRunning) {
80-
return false
81-
}
82-
if (isInlineCompletionEnabled() && RecommendationService.instance.isRunning) {
83-
return false
84-
}
85-
return true
86-
}
87-
8837
async processKeyStroke(
8938
event: vscode.TextDocumentChangeEvent,
9039
editor: vscode.TextEditor,

packages/core/src/shared/featureConfig.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const Features = {
3333
customizationArnOverride: 'customizationArnOverride',
3434
dataCollectionFeature: 'IDEProjectContextDataCollection',
3535
projectContextFeature: 'ProjectContextV2',
36+
newAutoTriggerUX: 'NewAutoTriggerUX',
3637
test: 'testFeature',
3738
} as const
3839

@@ -44,6 +45,7 @@ export const featureDefinitions = new Map<FeatureName, FeatureContext>([
4445
Features.customizationArnOverride,
4546
new FeatureContext(Features.customizationArnOverride, 'customizationARN', { stringValue: '' }),
4647
],
48+
[Features.newAutoTriggerUX, new FeatureContext(Features.newAutoTriggerUX, 'CONTROL', { stringValue: 'CONTROL' })],
4749
])
4850

4951
export class FeatureConfigProvider {
@@ -156,6 +158,14 @@ export class FeatureConfigProvider {
156158
globals.globalState.tryUpdate('aws.amazonq.workspaceIndexToggleOn', true)
157159
}
158160
}
161+
162+
const newAutoTriggerUXValue = this.featureConfigs.get(Features.newAutoTriggerUX)?.value.stringValue
163+
if (newAutoTriggerUXValue === 'TREATMENT') {
164+
// AB experiment only to builderId users
165+
if (isIdcSsoConnection(AuthUtil.instance.conn)) {
166+
this.featureConfigs.delete(Features.customizationArnOverride)
167+
}
168+
}
159169
} catch (e) {
160170
getLogger().error(`CodeWhisperer: Error when fetching feature configs ${e}`, e)
161171
}
@@ -189,6 +199,10 @@ export class FeatureConfigProvider {
189199
return this.getFeatureValueForKey(Features.customizationArnOverride).stringValue
190200
}
191201

202+
getNewAutoTriggerUX(): boolean {
203+
return this.getFeatureValueForKey(Features.newAutoTriggerUX).stringValue === 'TREATMENT'
204+
}
205+
192206
// Get the feature value for the given key.
193207
// In case of a misconfiguration, it will return a default feature value of Boolean true.
194208
private getFeatureValueForKey(name: FeatureName): FeatureValue {

0 commit comments

Comments
 (0)