Skip to content

Commit 683f08d

Browse files
authored
feat(codewhisperer): improve file context fetching logic #3567
Improve codewhisperer file context fetching logic for generating recommendations.
1 parent 97f39b1 commit 683f08d

39 files changed

+2160
-98
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "CodeWhisperer: Improve file context fetching logic"
4+
}

.changes/next-release/Feature-ce707655-611e-4a2f-997f-9d5b0472f7df.json

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

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3422,7 +3422,7 @@
34223422
"report": "nyc report --reporter=html --reporter=json"
34233423
},
34243424
"devDependencies": {
3425-
"@aws-toolkits/telemetry": "^1.0.129",
3425+
"@aws-toolkits/telemetry": "^1.0.130",
34263426
"@cspotcode/source-map-support": "^0.8.1",
34273427
"@sinonjs/fake-timers": "^10.0.2",
34283428
"@types/adm-zip": "^0.4.34",

src/codewhisperer/activation.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ export async function activate(context: ExtContext): Promise<void> {
6262

6363
if (isCloud9()) {
6464
await enableDefaultConfigCloud9()
65-
} else {
66-
determineUserGroup()
6765
}
66+
6867
/**
6968
* CodeWhisperer security panel
7069
*/
@@ -215,23 +214,6 @@ export async function activate(context: ExtContext): Promise<void> {
215214
)
216215
}
217216

218-
function determineUserGroup() {
219-
const userGroup = context.extensionContext.globalState.get<CodeWhispererConstants.UserGroup | undefined>(
220-
CodeWhispererConstants.userGroupKey
221-
)
222-
if (userGroup === undefined) {
223-
const randomNum = Math.random()
224-
const result =
225-
randomNum <= 1 / 3
226-
? CodeWhispererConstants.UserGroup.Control
227-
: randomNum <= 2 / 3
228-
? CodeWhispererConstants.UserGroup.CrossFile
229-
: CodeWhispererConstants.UserGroup.Classifier
230-
231-
context.extensionContext.globalState.update(CodeWhispererConstants.userGroupKey, result)
232-
}
233-
}
234-
235217
function getAutoTriggerStatus(): boolean {
236218
return context.extensionContext.globalState.get<boolean>(CodeWhispererConstants.autoTriggerEnabledKey) || false
237219
}

src/codewhisperer/client/codewhisperer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export type GetCodeScanRequest = Readonly<
4747
export type ListCodeScanFindingsRequest = Readonly<
4848
CodeWhispererClient.ListCodeScanFindingsRequest | CodeWhispererUserClient.ListCodeAnalysisFindingsRequest
4949
>
50+
export type SupplementalContext = Readonly<
51+
CodeWhispererClient.SupplementalContext | CodeWhispererUserClient.SupplementalContext
52+
>
5053
export type ArtifactType = Readonly<CodeWhispererClient.ArtifactType | CodeWhispererUserClient.ArtifactType>
5154
export type ArtifactMap = Readonly<CodeWhispererClient.ArtifactMap | CodeWhispererUserClient.ArtifactMap>
5255
export type ListCodeScanFindingsResponse =

src/codewhisperer/client/service-2.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,48 @@
635635
"min": 0,
636636
"sensitive": true
637637
},
638+
"SupplementalContext": {
639+
"type": "structure",
640+
"required": ["filePath", "content"],
641+
"members": {
642+
"filePath": {
643+
"shape": "SupplementalContextFilePathString"
644+
},
645+
"content": {
646+
"shape": "SupplementalContextContentString"
647+
}
648+
}
649+
},
650+
"SupplementalContextFilePathString": {
651+
"type": "string",
652+
"max": 1024,
653+
"min": 1,
654+
"sensitive": true
655+
},
656+
"SupplementalContextContentString": {
657+
"type": "string",
658+
"max": 5120,
659+
"min": 0,
660+
"sensitive": true
661+
},
662+
"SupplementalContextList": {
663+
"type": "list",
664+
"member": {
665+
"shape": "SupplementalContext"
666+
},
667+
"max": 10,
668+
"min": 0
669+
},
638670
"GenerateRecommendationsRequest": {
639671
"type": "structure",
640672
"required": ["fileContext"],
641673
"members": {
642674
"fileContext": {
643675
"shape": "FileContext"
644676
},
677+
"supplementalContexts": {
678+
"shape": "SupplementalContextList"
679+
},
645680
"maxResults": {
646681
"shape": "GenerateRecommendationsRequestMaxResultsInteger"
647682
},
@@ -855,6 +890,9 @@
855890
"maxResults": {
856891
"shape": "ListRecommendationsRequestMaxResultsInteger"
857892
},
893+
"supplementalContexts": {
894+
"shape": "SupplementalContextList"
895+
},
858896
"nextToken": {
859897
"shape": "ListRecommendationsRequestNextTokenString"
860898
},

src/codewhisperer/client/user-service-2.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,38 @@
330330
"min": 0,
331331
"sensitive": true
332332
},
333+
"SupplementalContext": {
334+
"type": "structure",
335+
"required": ["filePath", "content"],
336+
"members": {
337+
"filePath": {
338+
"shape": "SupplementalContextFilePathString"
339+
},
340+
"content": {
341+
"shape": "SupplementalContextContentString"
342+
}
343+
}
344+
},
345+
"SupplementalContextFilePathString": {
346+
"type": "string",
347+
"max": 1024,
348+
"min": 1,
349+
"sensitive": true
350+
},
351+
"SupplementalContextContentString": {
352+
"type": "string",
353+
"max": 5120,
354+
"min": 0,
355+
"sensitive": true
356+
},
357+
"SupplementalContextList": {
358+
"type": "list",
359+
"member": {
360+
"shape": "SupplementalContext"
361+
},
362+
"max": 10,
363+
"min": 0
364+
},
333365
"GenerateCompletionsRequest": {
334366
"type": "structure",
335367
"required": ["fileContext"],
@@ -345,6 +377,9 @@
345377
},
346378
"referenceTrackerConfiguration": {
347379
"shape": "ReferenceTrackerConfiguration"
380+
},
381+
"supplementalContexts": {
382+
"shape": "SupplementalContextList"
348383
}
349384
}
350385
},

src/codewhisperer/models/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const lineBreak = '\n'
5151

5252
export const lineBreakWin = '\r\n'
5353

54+
export const supplementalContextTimeoutInMs = 50
55+
5456
/**
5557
* Ux of recommendations
5658
*/
@@ -261,3 +263,7 @@ export enum UserGroup {
261263
CrossFile = 'CrossFile',
262264
Control = 'Control',
263265
}
266+
267+
export const isClassifierEnabledKey = 'CODEWHISPERER_CLASSIFIER_TRIGGER_ENABLED'
268+
269+
export const supplemetalContextFetchingTimeoutMsg = 'codewhisperer supplemental context fetching timeout'

src/codewhisperer/service/classifierTrigger.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
import * as os from 'os'
77
import * as vscode from 'vscode'
8-
import globals from '../../shared/extensionGlobals'
98
import { CodewhispererLanguage, CodewhispererAutomatedTriggerType } from '../../shared/telemetry/telemetry'
109
import { extractContextForCodeWhisperer } from '../util/editorContext'
1110
import { TelemetryHelper } from '../util/telemetryHelper'
1211
import * as CodeWhispererConstants from '../models/constants'
1312
import { runtimeLanguageContext } from '../util/runtimeLanguageContext'
1413
import { ProgrammingLanguage } from '../client/codewhispereruserclient'
14+
import { CodeWhispererUserGroupSettings } from '../util/userGroupUtil'
1515

1616
interface normalizedCoefficients {
1717
readonly cursor: number
@@ -318,12 +318,8 @@ export class ClassifierTrigger {
318318
this.lastInvocationLineNumber = lineNumber
319319
}
320320

321-
public isClassifierEnabled() {
322-
const userGroup = globals.context.globalState.get<CodeWhispererConstants.UserGroup | undefined>(
323-
CodeWhispererConstants.userGroupKey
324-
)
325-
326-
return userGroup === CodeWhispererConstants.UserGroup.Classifier
321+
public isClassifierEnabled(): boolean {
322+
return CodeWhispererUserGroupSettings.getUserGroup() === CodeWhispererConstants.UserGroup.Classifier
327323
}
328324

329325
public getThreshold() {

0 commit comments

Comments
 (0)