From 42154b210dfdafb3027e2f949d240784090ad64c Mon Sep 17 00:00:00 2001 From: Laxman Reddy <141967714+laileni-aws@users.noreply.github.com> Date: Wed, 19 Feb 2025 12:27:07 -0800 Subject: [PATCH 1/2] Updating logic for getWorkspaceRelativePath in shared src --- .../core/src/codewhisperer/util/zipUtil.ts | 11 ++++++++--- .../src/shared/utilities/workspaceUtils.ts | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/core/src/codewhisperer/util/zipUtil.ts b/packages/core/src/codewhisperer/util/zipUtil.ts index 7144ac3862c..54513fb06bc 100644 --- a/packages/core/src/codewhisperer/util/zipUtil.ts +++ b/packages/core/src/codewhisperer/util/zipUtil.ts @@ -410,9 +410,14 @@ export class ZipUtil { return } - const sourceFiles = await collectFiles(projectPaths, vscode.workspace.workspaceFolders as CurrentWsFolders, { - maxSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(), - }) + const sourceFiles = await collectFiles( + projectPaths, + vscode.workspace.workspaceFolders as CurrentWsFolders, + { + maxSizeBytes: this.getProjectScanPayloadSizeLimitInBytes(), + }, + useCase + ) for (const file of sourceFiles) { const projectName = path.basename(file.workspaceFolder.uri.fsPath) const zipEntryPath = this.getZipEntryPath(projectName, file.relativeFilePath) diff --git a/packages/core/src/shared/utilities/workspaceUtils.ts b/packages/core/src/shared/utilities/workspaceUtils.ts index 46db8dd3a74..41577648dd2 100644 --- a/packages/core/src/shared/utilities/workspaceUtils.ts +++ b/packages/core/src/shared/utilities/workspaceUtils.ts @@ -20,6 +20,7 @@ import fs from '../fs/fs' import { ChildProcess } from './processUtils' import { isWin } from '../vscode/env' import { maxRepoSizeBytes } from '../../amazonqFeatureDev/constants' +import { FeatureUseCase } from '../../codewhisperer/models/constants' type GitIgnoreRelativeAcceptor = { folderPath: string @@ -223,12 +224,20 @@ export function getWorkspaceRelativePath( workspaceFolders?: readonly vscode.WorkspaceFolder[] } = { workspaceFolders: vscode.workspace.workspaceFolders, - } + }, + useCase?: FeatureUseCase ): { relativePath: string; workspaceFolder: vscode.WorkspaceFolder } | undefined { if (!override.workspaceFolders) { return } - for (const folder of override.workspaceFolders) { + let folders = override.workspaceFolders + if (useCase && useCase === FeatureUseCase.TEST_GENERATION) { + // Sort workspace folders by path length (descending) to prioritize deeper paths + // TODO: Need to enable this for entire Q + folders = [...override.workspaceFolders].sort((a, b) => b.uri.fsPath.length - a.uri.fsPath.length) + } + + for (const folder of folders) { if (isInDirectory(folder.uri.fsPath, childPath)) { return { relativePath: path.relative(folder.uri.fsPath, childPath), workspaceFolder: folder } } @@ -352,7 +361,8 @@ export async function collectFiles( excludeByGitIgnore?: boolean // default true excludePatterns?: string[] // default defaultExcludePatterns filterFn?: CollectFilesFilter - } + }, + useCase?: FeatureUseCase ): Promise { const storage: Awaited = [] @@ -398,7 +408,7 @@ export async function collectFiles( const files = excludeByGitIgnore ? await filterOutGitignoredFiles(rootPath, allFiles, false) : allFiles for (const file of files) { - const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders }) + const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders }, useCase) if (!relativePath) { continue } From 3bb0d28eac47679f39c548caac1fec838a65c5ed Mon Sep 17 00:00:00 2001 From: Laxman Reddy <141967714+laileni-aws@users.noreply.github.com> Date: Wed, 19 Feb 2025 12:44:23 -0800 Subject: [PATCH 2/2] Adding changelog --- .../Bug Fix-ee447a9f-6a92-47c5-8e94-069c1aee46ab.json | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/amazonq/.changes/next-release/Bug Fix-ee447a9f-6a92-47c5-8e94-069c1aee46ab.json diff --git a/packages/amazonq/.changes/next-release/Bug Fix-ee447a9f-6a92-47c5-8e94-069c1aee46ab.json b/packages/amazonq/.changes/next-release/Bug Fix-ee447a9f-6a92-47c5-8e94-069c1aee46ab.json new file mode 100644 index 00000000000..3492ea1866c --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-ee447a9f-6a92-47c5-8e94-069c1aee46ab.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Amazon Q /test: Fixing the issue of target file does not exist." +}