Skip to content

Commit 23adb44

Browse files
authored
feat(codewhisperer): enable UTG (Unit test generator) for java/python (#3651)
* Enable UTG (unit test generator) feature flag for CrossFile userGroup * Make changes to ensure supplemental context telemetry being sent regardless the userGroup it belongs (we need `metadata.codewhispererSupplementalContextIsUtg` field to differentiate UTG feature acceptance rate vs. CrossFile feature)
1 parent 219c586 commit 23adb44

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
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 suggestion quality with enhanced file context fetching"
4+
}

src/codewhisperer/util/editorContext.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ import {
1616
fetchSupplementalContext,
1717
} from './supplementalContext/supplementalContextUtil'
1818
import { supplementalContextTimeoutInMs } from '../models/constants'
19-
import { CodeWhispererUserGroupSettings } from './userGroupUtil'
20-
import { isTestFile } from './supplementalContext/codeParsingUtil'
21-
import { DependencyGraphFactory } from './dependencyGraph/dependencyGraphFactory'
2219
import { selectFrom } from '../../shared/utilities/tsUtils'
2320

2421
let tabSize: number = getTabSizeSetting()
@@ -90,14 +87,7 @@ export async function buildListRecommendationRequest(
9087
tokenSource.cancel()
9188
}, supplementalContextTimeoutInMs)
9289

93-
// Send Cross file context to CodeWhisperer service if and only if
94-
// (1) User is CrossFile user group
95-
// (2) The supplemental context is from Supplemental Context but not UTG(unit test generator)
96-
const isUtg = await isTestFile(editor, DependencyGraphFactory.getDependencyGraph(editor.document.languageId))
97-
const supplementalContexts: CodeWhispererSupplementalContext | undefined =
98-
CodeWhispererUserGroupSettings.getUserGroup() === CodeWhispererConstants.UserGroup.CrossFile && !isUtg
99-
? await fetchSupplementalContext(editor, tokenSource.token)
100-
: undefined
90+
const supplementalContexts = await fetchSupplementalContext(editor, tokenSource.token)
10191

10292
const suppelmetalMetadata: Omit<CodeWhispererSupplementalContext, 'supplementalContextItems'> | undefined =
10393
supplementalContexts

src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { DependencyGraph } from '../dependencyGraph/dependencyGraph'
99
import { BM25Document, BM25Okapi } from './rankBm25'
1010
import { isRelevant } from './editorFilesUtil'
1111
import { ToolkitError } from '../../../shared/errors'
12-
import { crossFileContextConfig, supplemetalContextFetchingTimeoutMsg } from '../../models/constants'
12+
import { UserGroup, crossFileContextConfig, supplemetalContextFetchingTimeoutMsg } from '../../models/constants'
1313
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
1414
import { CodeWhispererSupplementalContextItem } from './supplementalContextUtil'
15+
import { CodeWhispererUserGroupSettings } from '../userGroupUtil'
1516

1617
const crossFileLanguageConfigs = ['java']
1718
interface Chunk {
@@ -30,6 +31,10 @@ export async function fetchSupplementalContextForSrc(
3031
return undefined
3132
}
3233

34+
if (CodeWhispererUserGroupSettings.instance.userGroup !== UserGroup.CrossFile) {
35+
return []
36+
}
37+
3338
// Step 1: Get relevant cross files to refer
3439
const relevantCrossFilePaths = await getRelevantCrossFiles(editor, dependencyGraph)
3540
throwIfCancelled(cancellationToken)

src/codewhisperer/util/supplementalContext/utgUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { supplemetalContextFetchingTimeoutMsg } from '../../models/constants'
2121
import { CancellationError } from '../../../shared/utilities/timeoutUtils'
2222
import { CodeWhispererSupplementalContextItem } from './supplementalContextUtil'
2323
import { utgConfig } from '../../models/constants'
24+
import { CodeWhispererUserGroupSettings } from '../userGroupUtil'
25+
import { UserGroup } from '../../models/constants'
2426

2527
/**
2628
* This function attempts to find a focal file for the given trigger file.
@@ -51,6 +53,10 @@ export async function fetchSupplementalContextForTest(
5153
return undefined
5254
}
5355

56+
if (CodeWhispererUserGroupSettings.instance.userGroup !== UserGroup.CrossFile) {
57+
return []
58+
}
59+
5460
// TODO (Metrics): 1. Total number of calls to fetchSupplementalContextForTest
5561
throwIfCancelled(cancellationToken)
5662

0 commit comments

Comments
 (0)