Skip to content

Commit 6a27e29

Browse files
authored
codewhisperer: dial up java utg support #3710
1 parent b2c1fdf commit 6a27e29

File tree

3 files changed

+78
-15
lines changed

3 files changed

+78
-15
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 for Java test files"
4+
}

src/codewhisperer/util/supplementalContext/utgUtils.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ import { CodeWhispererUserGroupSettings } from '../userGroupUtil'
2424
import { UserGroup } from '../../models/constants'
2525
import { getOpenFilesInWindow } from '../../../shared/utilities/editorUtilities'
2626

27+
type UtgSupportedLanguage = keyof typeof utgLanguageConfigs
28+
29+
function isUtgSupportedLanguage(languageId: vscode.TextDocument['languageId']): languageId is UtgSupportedLanguage {
30+
return languageId in utgLanguageConfigs
31+
}
32+
33+
export function shouldFetchUtgContext(
34+
languageId: vscode.TextDocument['languageId'],
35+
userGroup: UserGroup
36+
): boolean | undefined {
37+
if (!isUtgSupportedLanguage(languageId)) {
38+
return undefined
39+
}
40+
41+
if (languageId === 'java') {
42+
return true
43+
} else {
44+
return userGroup === UserGroup.CrossFile
45+
}
46+
}
47+
2748
/**
2849
* This function attempts to find a focal file for the given trigger file.
2950
* Attempt 1: If naming patterns followed correctly, source file can be found by name referencing.
@@ -37,24 +58,16 @@ export async function fetchSupplementalContextForTest(
3758
editor: vscode.TextEditor,
3859
cancellationToken: vscode.CancellationToken
3960
): Promise<CodeWhispererSupplementalContextItem[] | undefined> {
40-
// TODO: Add metrices
41-
// 1. Total number of calls to fetchSupplementalContextForTest
42-
// 2. Success count for fetchSourceFileByName (find source file by name)
43-
// 3. Success count for fetchSourceFileByContent (find source file by content)
44-
// 4. Failure count - when unable to find focal file (supplemental context empty)
61+
const shouldProceed = shouldFetchUtgContext(
62+
editor.document.languageId,
63+
CodeWhispererUserGroupSettings.instance.userGroup
64+
)
4565

46-
const languageConfig = utgLanguageConfigs[editor.document.languageId]
47-
if (!languageConfig) {
48-
// This is required because we are launching this support for even smaller subset of
49-
// supported languages.
50-
// TODO: Add a metrics to see number of calls falling in this bucket.
51-
// TODO: Either catch this error upstream or here.
52-
return undefined
66+
if (!shouldProceed) {
67+
return shouldProceed === undefined ? undefined : []
5368
}
5469

55-
if (CodeWhispererUserGroupSettings.instance.userGroup !== UserGroup.CrossFile) {
56-
return []
57-
}
70+
const languageConfig = utgLanguageConfigs[editor.document.languageId]
5871

5972
// TODO (Metrics): 1. Total number of calls to fetchSupplementalContextForTest
6073
throwIfCancelled(cancellationToken)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as assert from 'assert'
7+
import * as utgUtils from '../../../codewhisperer/util/supplementalContext/utgUtils'
8+
import { UserGroup } from '../../../codewhisperer/models/constants'
9+
10+
describe('shouldFetchUtgContext', () => {
11+
it('fully supported language', function () {
12+
assert.ok(utgUtils.shouldFetchUtgContext('java', UserGroup.Control))
13+
assert.ok(utgUtils.shouldFetchUtgContext('java', UserGroup.CrossFile))
14+
})
15+
16+
it('partially supported language', () => {
17+
assert.strictEqual(utgUtils.shouldFetchUtgContext('python', UserGroup.Control), false)
18+
assert.strictEqual(utgUtils.shouldFetchUtgContext('python', UserGroup.CrossFile), true)
19+
})
20+
21+
it('not supported language', () => {
22+
assert.strictEqual(utgUtils.shouldFetchUtgContext('typescript', UserGroup.Control), undefined)
23+
assert.strictEqual(utgUtils.shouldFetchUtgContext('typescript', UserGroup.CrossFile), undefined)
24+
25+
assert.strictEqual(utgUtils.shouldFetchUtgContext('javascript', UserGroup.Control), undefined)
26+
assert.strictEqual(utgUtils.shouldFetchUtgContext('javascript', UserGroup.CrossFile), undefined)
27+
28+
assert.strictEqual(utgUtils.shouldFetchUtgContext('javascriptreact', UserGroup.Control), undefined)
29+
assert.strictEqual(utgUtils.shouldFetchUtgContext('javascriptreact', UserGroup.CrossFile), undefined)
30+
31+
assert.strictEqual(utgUtils.shouldFetchUtgContext('typescriptreact', UserGroup.Control), undefined)
32+
assert.strictEqual(utgUtils.shouldFetchUtgContext('typescriptreact', UserGroup.CrossFile), undefined)
33+
34+
assert.strictEqual(utgUtils.shouldFetchUtgContext('scala', UserGroup.Control), undefined)
35+
assert.strictEqual(utgUtils.shouldFetchUtgContext('scala', UserGroup.CrossFile), undefined)
36+
37+
assert.strictEqual(utgUtils.shouldFetchUtgContext('shellscript', UserGroup.Control), undefined)
38+
assert.strictEqual(utgUtils.shouldFetchUtgContext('shellscript', UserGroup.CrossFile), undefined)
39+
40+
assert.strictEqual(utgUtils.shouldFetchUtgContext('csharp', UserGroup.Control), undefined)
41+
assert.strictEqual(utgUtils.shouldFetchUtgContext('csharp', UserGroup.CrossFile), undefined)
42+
43+
assert.strictEqual(utgUtils.shouldFetchUtgContext('c', UserGroup.Control), undefined)
44+
assert.strictEqual(utgUtils.shouldFetchUtgContext('c', UserGroup.CrossFile), undefined)
45+
})
46+
})

0 commit comments

Comments
 (0)