Skip to content

Commit

Permalink
feat(amazonq): new auto trigger UX feature config changes
Browse files Browse the repository at this point in the history
1. also removed idleTrigger type as it's not being used anywhere
  • Loading branch information
andrewyuq committed Oct 31, 2024
1 parent 9fd91dd commit 2ca4e5e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
DocumentChangedSource,
KeyStrokeHandler,
DefaultDocumentChangedType,
RecommendationService,
ClassifierTrigger,
isInlineCompletionEnabled,
RecommendationHandler,
Expand All @@ -37,11 +36,9 @@ describe('keyStrokeHandler', function () {
})
describe('processKeyStroke', async function () {
let invokeSpy: sinon.SinonStub
let startTimerSpy: sinon.SinonStub
let mockClient: codewhispererSdkClient.DefaultCodeWhispererClient
beforeEach(async function () {
invokeSpy = sinon.stub(KeyStrokeHandler.instance, 'invokeAutomatedTrigger')
startTimerSpy = sinon.stub(KeyStrokeHandler.instance, 'startIdleTimeTriggerTimer')
sinon.spy(RecommendationHandler.instance, 'getRecommendations')
mockClient = new codewhispererSdkClient.DefaultCodeWhispererClient()
await resetCodeWhispererGlobalVariables()
Expand All @@ -68,7 +65,6 @@ describe('keyStrokeHandler', function () {
const keyStrokeHandler = new KeyStrokeHandler()
await keyStrokeHandler.processKeyStroke(mockEvent, mockEditor, mockClient, cfg)
assert.ok(!invokeSpy.called)
assert.ok(!startTimerSpy.called)
})

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

describe('shouldTriggerIdleTime', function () {
it('should return false when inline is enabled and inline completion is in progress ', function () {
const keyStrokeHandler = new KeyStrokeHandler()
sinon.stub(RecommendationService.instance, 'isRunning').get(() => true)
const result = keyStrokeHandler.shouldTriggerIdleTime()
assert.strictEqual(result, !isInlineCompletionEnabled())
})
})

describe('test checkChangeSource', function () {
const tabStr = ' '.repeat(EditorContext.getTabSize())

Expand Down
51 changes: 0 additions & 51 deletions packages/core/src/codewhisperer/service/keyStrokeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@

import * as vscode from 'vscode'
import { DefaultCodeWhispererClient } from '../client/codewhisperer'
import * as CodeWhispererConstants from '../models/constants'
import { ConfigurationEntry } from '../models/model'
import { getLogger } from '../../shared/logger'
import { isCloud9 } from '../../shared/extensionUtilities'
import { RecommendationHandler } from './recommendationHandler'
import { CodewhispererAutomatedTriggerType } from '../../shared/telemetry/telemetry'
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
import { isInlineCompletionEnabled } from '../util/commonUtil'
import { ClassifierTrigger } from './classifierTrigger'
import { extractContextForCodeWhisperer } from '../util/editorContext'
import { RecommendationService } from './recommendationService'
Expand All @@ -25,12 +22,6 @@ export class KeyStrokeHandler {
* Special character which automated triggers codewhisperer
*/
public specialChar: string
/**
* Key stroke count for automated trigger
*/

private idleTriggerTimer?: NodeJS.Timer

public lastInvocationTime?: number

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

public startIdleTimeTriggerTimer(
event: vscode.TextDocumentChangeEvent,
editor: vscode.TextEditor,
client: DefaultCodeWhispererClient,
config: ConfigurationEntry
) {
if (this.idleTriggerTimer) {
clearInterval(this.idleTriggerTimer)
this.idleTriggerTimer = undefined
}
if (!this.shouldTriggerIdleTime()) {
return
}
this.idleTriggerTimer = setInterval(() => {
const duration = (performance.now() - RecommendationHandler.instance.lastInvocationTime) / 1000
if (duration < CodeWhispererConstants.invocationTimeIntervalThreshold) {
return
}

this.invokeAutomatedTrigger('IdleTime', editor, client, config, event)
.catch((e) => {
getLogger().error('invokeAutomatedTrigger failed: %s', (e as Error).message)
})
.finally(() => {
if (this.idleTriggerTimer) {
clearInterval(this.idleTriggerTimer)
this.idleTriggerTimer = undefined
}
})
}, CodeWhispererConstants.idleTimerPollPeriod)
}

public shouldTriggerIdleTime(): boolean {
if (isCloud9() && RecommendationService.instance.isRunning) {
return false
}
if (isInlineCompletionEnabled() && RecommendationService.instance.isRunning) {
return false
}
return true
}

async processKeyStroke(
event: vscode.TextDocumentChangeEvent,
editor: vscode.TextEditor,
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/shared/featureConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const Features = {
customizationArnOverride: 'customizationArnOverride',
dataCollectionFeature: 'IDEProjectContextDataCollection',
projectContextFeature: 'ProjectContextV2',
newAutoTriggerUX: 'NewAutoTriggerUX',
test: 'testFeature',
} as const

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

export class FeatureConfigProvider {
Expand Down Expand Up @@ -156,6 +158,14 @@ export class FeatureConfigProvider {
globals.globalState.tryUpdate('aws.amazonq.workspaceIndexToggleOn', true)
}
}

const newAutoTriggerUXValue = this.featureConfigs.get(Features.newAutoTriggerUX)?.value.stringValue
if (newAutoTriggerUXValue === 'TREATMENT') {
// AB experiment only to builderId users
if (isIdcSsoConnection(AuthUtil.instance.conn)) {
this.featureConfigs.delete(Features.customizationArnOverride)
}
}
} catch (e) {
getLogger().error(`CodeWhisperer: Error when fetching feature configs ${e}`, e)
}
Expand Down Expand Up @@ -189,6 +199,10 @@ export class FeatureConfigProvider {
return this.getFeatureValueForKey(Features.customizationArnOverride).stringValue
}

getNewAutoTriggerUX(): boolean {
return this.getFeatureValueForKey(Features.newAutoTriggerUX).stringValue === 'TREATMENT'
}

// Get the feature value for the given key.
// In case of a misconfiguration, it will return a default feature value of Boolean true.
private getFeatureValueForKey(name: FeatureName): FeatureValue {
Expand Down

0 comments on commit 2ca4e5e

Please sign in to comment.