@@ -391,7 +391,7 @@ export async function collectFiles(
391391 }
392392
393393 let totalSizeBytes = 0
394- const storage = [ ]
394+ const storage : ( Omit < CollectFilesResultItem , 'fileContent' > | CollectFilesResultItem ) [ ] = [ ]
395395 const excludePatternFilter = excludePatternsAsString ( excludePatterns )
396396 for ( const rootPath of sourcePaths ) {
397397 const allFiles = await vscode . workspace . findFiles (
@@ -432,19 +432,21 @@ export async function collectFiles(
432432 isText : ! ZipConstants . knownBinaryFileExts . includes ( path . extname ( file . fsPath ) ) ,
433433 }
434434 if ( includeContent ) {
435- const content = await readFile ( file )
435+ const hasUnsavedChanges = isFileOpenAndDirty ( file )
436+ const content =
437+ result . isText && hasUnsavedChanges ? await getCurrentTextContent ( file ) : await readFile ( file )
436438 if ( content === undefined ) {
437439 continue
438440 }
439- totalSizeBytes += fileStat . size
441+
440442 storage . push ( {
441443 ...result ,
442444 fileContent : content ,
443445 } )
444446 } else {
445- totalSizeBytes += fileStat . size
446447 storage . push ( result )
447448 }
449+ totalSizeBytes += fileStat . size
448450 }
449451 }
450452 return storage
@@ -463,6 +465,16 @@ export async function collectFiles(
463465 }
464466 return prefix === '' ? path : `${ prefix } /${ path } `
465467 }
468+
469+ async function getCurrentTextContent ( uri : vscode . Uri ) {
470+ const document = await vscode . workspace . openTextDocument ( uri )
471+ const content = document . getText ( )
472+ return content
473+ }
474+
475+ function isFileOpenAndDirty ( uri : vscode . Uri ) {
476+ return vscode . workspace . textDocuments . some ( ( document ) => document . uri . fsPath === uri . fsPath && document . isDirty )
477+ }
466478}
467479
468480const readFile = async ( file : vscode . Uri ) => {
0 commit comments