@@ -20,6 +20,7 @@ import fs from '../fs/fs'
2020import { ChildProcess } from './processUtils'
2121import { isWin } from '../vscode/env'
2222import { maxRepoSizeBytes } from '../../amazonqFeatureDev/constants'
23+ import { FeatureUseCase } from '../../codewhisperer/models/constants'
2324
2425type 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