Skip to content

Commit 302b142

Browse files
Merge master into feature/serverlessland
2 parents 359e90e + 35452cd commit 302b142

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q /test: Fixing the issue of target file does not exist."
4+
}

packages/core/src/codewhisperer/util/zipUtil.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,14 @@ export class ZipUtil {
410410
return
411411
}
412412

413-
const sourceFiles = await collectFiles(projectPaths, vscode.workspace.workspaceFolders as CurrentWsFolders, {
414-
maxSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(),
415-
})
413+
const sourceFiles = await collectFiles(
414+
projectPaths,
415+
vscode.workspace.workspaceFolders as CurrentWsFolders,
416+
{
417+
maxSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(),
418+
},
419+
useCase
420+
)
416421
for (const file of sourceFiles) {
417422
const projectName = path.basename(file.workspaceFolder.uri.fsPath)
418423
const zipEntryPath = this.getZipEntryPath(projectName, file.relativeFilePath)

packages/core/src/shared/utilities/workspaceUtils.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import fs from '../fs/fs'
2020
import { ChildProcess } from './processUtils'
2121
import { isWin } from '../vscode/env'
2222
import { maxRepoSizeBytes } from '../../amazonqFeatureDev/constants'
23+
import { FeatureUseCase } from '../../codewhisperer/models/constants'
2324

2425
type GitIgnoreRelativeAcceptor = {
2526
folderPath: string
@@ -223,12 +224,20 @@ export function getWorkspaceRelativePath(
223224
workspaceFolders?: readonly vscode.WorkspaceFolder[]
224225
} = {
225226
workspaceFolders: vscode.workspace.workspaceFolders,
226-
}
227+
},
228+
useCase?: FeatureUseCase
227229
): { relativePath: string; workspaceFolder: vscode.WorkspaceFolder } | undefined {
228230
if (!override.workspaceFolders) {
229231
return
230232
}
231-
for (const folder of override.workspaceFolders) {
233+
let folders = override.workspaceFolders
234+
if (useCase && useCase === FeatureUseCase.TEST_GENERATION) {
235+
// Sort workspace folders by path length (descending) to prioritize deeper paths
236+
// TODO: Need to enable this for entire Q
237+
folders = [...override.workspaceFolders].sort((a, b) => b.uri.fsPath.length - a.uri.fsPath.length)
238+
}
239+
240+
for (const folder of folders) {
232241
if (isInDirectory(folder.uri.fsPath, childPath)) {
233242
return { relativePath: path.relative(folder.uri.fsPath, childPath), workspaceFolder: folder }
234243
}
@@ -352,7 +361,8 @@ export async function collectFiles(
352361
excludeByGitIgnore?: boolean // default true
353362
excludePatterns?: string[] // default defaultExcludePatterns
354363
filterFn?: CollectFilesFilter
355-
}
364+
},
365+
useCase?: FeatureUseCase
356366
): Promise<CollectFilesResultItem[]> {
357367
const storage: Awaited<CollectFilesResultItem[]> = []
358368

@@ -398,7 +408,7 @@ export async function collectFiles(
398408
const files = excludeByGitIgnore ? await filterOutGitignoredFiles(rootPath, allFiles, false) : allFiles
399409

400410
for (const file of files) {
401-
const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders })
411+
const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders }, useCase)
402412
if (!relativePath) {
403413
continue
404414
}

0 commit comments

Comments
 (0)