Skip to content

Commit 86226e4

Browse files
authored
codewhisperer: enable complete .py .js .jsx .ts .tsx crossfile support (#3736)
1 parent f9ae7cf commit 86226e4

File tree

3 files changed

+54
-41
lines changed

3 files changed

+54
-41
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 Python Typescript Javascript source files"
4+
}

src/codewhisperer/util/supplementalContext/crossFileContextUtil.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,15 @@ function getInputChunk(editor: vscode.TextEditor, chunkSize: number) {
143143
* @returns specifically returning undefined if the langueage is not supported,
144144
* otherwise true/false depending on if the language is fully supported or not belonging to the user group
145145
*/
146-
function shouldFetchCrossFileContext(languageId: string, userGroup: UserGroup): boolean | undefined {
146+
function shouldFetchCrossFileContext(
147+
languageId: vscode.TextDocument['languageId'],
148+
userGroup: UserGroup
149+
): boolean | undefined {
147150
if (!isCrossFileSupported(languageId)) {
148151
return undefined
149152
}
150153

151-
if (languageId === 'java') {
152-
return true
153-
} else if (supportedLanguageToDialects[languageId] && userGroup === UserGroup.CrossFile) {
154-
return true
155-
} else {
156-
return false
157-
}
154+
return true
158155
}
159156

160157
/**

src/test/codewhisperer/util/crossFileContextUtil.test.ts

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ describe('crossFileContextUtil', function () {
123123
})
124124

125125
describe('partial support - control group', function () {
126+
const fileExtLists: string[] = []
127+
126128
before(async function () {
127129
this.timeout(60000)
128130
userGroupSettings.userGroup = UserGroup.Control
@@ -136,25 +138,29 @@ describe('crossFileContextUtil', function () {
136138
await closeAllEditors()
137139
})
138140

139-
it('should be empty if userGroup is control', async function () {
140-
if (!shouldRunTheTest()) {
141-
this.skip()
142-
}
141+
fileExtLists.forEach(fileExt => {
142+
it('should be empty if userGroup is control', async function () {
143+
if (!shouldRunTheTest()) {
144+
this.skip()
145+
}
143146

144-
const editor = await openATextEditorWithText('content-1', 'file-1.js', tempFolder, { preview: false })
145-
await openATextEditorWithText('content-2', 'file-2.js', tempFolder, { preview: false })
146-
await openATextEditorWithText('content-3', 'file-3.js', tempFolder, { preview: false })
147-
await openATextEditorWithText('content-4', 'file-4.js', tempFolder, { preview: false })
147+
const editor = await openATextEditorWithText('content-1', `file-1.${fileExt}`, tempFolder)
148+
await openATextEditorWithText('content-2', `file-2.${fileExt}`, tempFolder, { preview: false })
149+
await openATextEditorWithText('content-3', `file-3.${fileExt}`, tempFolder, { preview: false })
150+
await openATextEditorWithText('content-4', `file-4.${fileExt}`, tempFolder, { preview: false })
148151

149-
await assertTabCount(4)
152+
await assertTabCount(4)
150153

151-
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
154+
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
152155

153-
assert.ok(actual !== undefined && actual.length === 0)
156+
assert.ok(actual?.length !== undefined && actual.length === 0)
157+
})
154158
})
155159
})
156160

157161
describe('partial support - crossfile group', function () {
162+
const fileExtLists: string[] = []
163+
158164
before(async function () {
159165
this.timeout(60000)
160166
userGroupSettings.userGroup = UserGroup.CrossFile
@@ -168,25 +174,29 @@ describe('crossFileContextUtil', function () {
168174
await closeAllEditors()
169175
})
170176

171-
it('should be non empty if userGroup is crossfile', async function () {
172-
if (!shouldRunTheTest()) {
173-
this.skip()
174-
}
177+
fileExtLists.forEach(fileExt => {
178+
it('should be non empty if usergroup is Crossfile', async function () {
179+
if (!shouldRunTheTest()) {
180+
this.skip()
181+
}
175182

176-
const editor = await openATextEditorWithText('content-1', 'file-1.js', tempFolder, { preview: false })
177-
await openATextEditorWithText('content-2', 'file-2.js', tempFolder, { preview: false })
178-
await openATextEditorWithText('content-3', 'file-3.js', tempFolder, { preview: false })
179-
await openATextEditorWithText('content-4', 'file-4.js', tempFolder, { preview: false })
183+
const editor = await openATextEditorWithText('content-1', `file-1.${fileExt}`, tempFolder)
184+
await openATextEditorWithText('content-2', `file-2.${fileExt}`, tempFolder, { preview: false })
185+
await openATextEditorWithText('content-3', `file-3.${fileExt}`, tempFolder, { preview: false })
186+
await openATextEditorWithText('content-4', `file-4.${fileExt}`, tempFolder, { preview: false })
180187

181-
await assertTabCount(4)
188+
await assertTabCount(4)
182189

183-
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
190+
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
184191

185-
assert.ok(actual !== undefined && actual.length !== 0)
192+
assert.ok(actual?.length !== undefined && actual.length !== 0)
193+
})
186194
})
187195
})
188196

189197
describe('full support', function () {
198+
const fileExtLists = ['java', 'js', 'ts', 'py', 'tsx', 'jsx']
199+
190200
before(async function () {
191201
this.timeout(60000)
192202
})
@@ -200,21 +210,23 @@ describe('crossFileContextUtil', function () {
200210
await closeAllEditors()
201211
})
202212

203-
it('should be non empty', async function () {
204-
if (!shouldRunTheTest()) {
205-
this.skip()
206-
}
213+
fileExtLists.forEach(fileExt => {
214+
it('should be non empty', async function () {
215+
if (!shouldRunTheTest()) {
216+
this.skip()
217+
}
207218

208-
const editor = await openATextEditorWithText('content-1', 'file-1.java', tempFolder)
209-
await openATextEditorWithText('content-2', 'file-2.java', tempFolder, { preview: false })
210-
await openATextEditorWithText('content-3', 'file-3.java', tempFolder, { preview: false })
211-
await openATextEditorWithText('content-4', 'file-4.java', tempFolder, { preview: false })
219+
const editor = await openATextEditorWithText('content-1', `file-1.${fileExt}`, tempFolder)
220+
await openATextEditorWithText('content-2', `file-2.${fileExt}`, tempFolder, { preview: false })
221+
await openATextEditorWithText('content-3', `file-3.${fileExt}`, tempFolder, { preview: false })
222+
await openATextEditorWithText('content-4', `file-4.${fileExt}`, tempFolder, { preview: false })
212223

213-
await assertTabCount(4)
224+
await assertTabCount(4)
214225

215-
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
226+
const actual = await crossFile.fetchSupplementalContextForSrc(editor, fakeCancellationToken)
216227

217-
assert.ok(actual?.length !== undefined && actual.length !== 0)
228+
assert.ok(actual?.length !== undefined && actual.length !== 0)
229+
})
218230
})
219231
})
220232
})

0 commit comments

Comments
 (0)