@@ -21,6 +21,7 @@ import { ChildProcess } from './processUtils'
2121import { isWin } from '../vscode/env'
2222import { maxRepoSizeBytes } from '../../amazonqFeatureDev/constants'
2323import { ZipConstants } from '../../codewhisperer/util/zipUtil'
24+ import { isFileOpenAndDirty } from '../../amazonq/util/zipProjectUtil'
2425
2526type GitIgnoreRelativeAcceptor = {
2627 folderPath : string
@@ -391,7 +392,7 @@ export async function collectFiles(
391392 }
392393
393394 let totalSizeBytes = 0
394- const storage = [ ]
395+ const storage : ( Omit < CollectFilesResultItem , 'fileContent' > | CollectFilesResultItem ) [ ] = [ ]
395396 const excludePatternFilter = excludePatternsAsString ( excludePatterns )
396397 for ( const rootPath of sourcePaths ) {
397398 const allFiles = await vscode . workspace . findFiles (
@@ -432,19 +433,21 @@ export async function collectFiles(
432433 isText : ! ZipConstants . knownBinaryFileExts . includes ( path . extname ( file . fsPath ) ) ,
433434 }
434435 if ( includeContent ) {
435- const content = await readFile ( file )
436+ const hasUnsavedChanges = isFileOpenAndDirty ( file )
437+ const content =
438+ result . isText && hasUnsavedChanges ? await getCurrentTextContent ( file ) : await readFile ( file )
436439 if ( content === undefined ) {
437440 continue
438441 }
439- totalSizeBytes += fileStat . size
442+
440443 storage . push ( {
441444 ...result ,
442445 fileContent : content ,
443446 } )
444447 } else {
445- totalSizeBytes += fileStat . size
446448 storage . push ( result )
447449 }
450+ totalSizeBytes += fileStat . size
448451 }
449452 }
450453 return storage
@@ -463,6 +466,12 @@ export async function collectFiles(
463466 }
464467 return prefix === '' ? path : `${ prefix } /${ path } `
465468 }
469+
470+ async function getCurrentTextContent ( uri : vscode . Uri ) {
471+ const document = await vscode . workspace . openTextDocument ( uri )
472+ const content = document . getText ( )
473+ return content
474+ }
466475}
467476
468477const readFile = async ( file : vscode . Uri ) => {
0 commit comments