@@ -12,7 +12,13 @@ import { fs } from '../../shared/fs/fs'
1212import { getLoggerForScope } from '../service/securityScanHandler'
1313import { runtimeLanguageContext } from './runtimeLanguageContext'
1414import { CodewhispererLanguage } from '../../shared/telemetry/telemetry.gen'
15- import { CurrentWsFolders , collectFiles , defaultExcludePatterns } from '../../shared/utilities/workspaceUtils'
15+ import {
16+ CollectFilesOptions ,
17+ CollectFilesResultItem ,
18+ CurrentWsFolders ,
19+ collectFiles ,
20+ defaultExcludePatterns ,
21+ } from '../../shared/utilities/workspaceUtils'
1622import {
1723 FileSizeExceededError ,
1824 NoActiveFileError ,
@@ -419,54 +425,56 @@ export class ZipUtil {
419425 : vscode . workspace . workspaceFolders
420426 ) as CurrentWsFolders
421427
422- const collectFilesOptions = {
428+ const collectFilesOptions : CollectFilesOptions = {
423429 maxTotalSizeBytes : this . getProjectScanPayloadSizeLimitInBytes ( ) ,
424430 excludePatterns :
425431 useCase === FeatureUseCase . TEST_GENERATION
426432 ? [ ...CodeWhispererConstants . testGenExcludePatterns , ...defaultExcludePatterns ]
427433 : defaultExcludePatterns ,
434+ includeContent : true ,
435+ }
436+ const isExcluded = ( file : CollectFilesResultItem ) =>
437+ ZipConstants . knownBinaryFileExts . includes ( path . extname ( file . fileUri . fsPath ) ) &&
438+ useCase === FeatureUseCase . TEST_GENERATION
439+
440+ const checkForError = ( file : CollectFilesResultItem ) =>
441+ this . reachSizeLimit ( this . _totalSize , CodeWhispererConstants . CodeAnalysisScope . PROJECT ) ||
442+ this . willReachSizeLimit ( this . _totalSize , file . fileSizeBytes )
443+ ? new ProjectSizeExceededError ( )
444+ : undefined
445+
446+ const computeSideEffects = ( file : CollectFilesResultItem ) => {
447+ if ( file . isText ) {
448+ this . _totalLines += file . fileContent . split ( ZipConstants . newlineRegex ) . length
449+ this . incrementCountForLanguage ( file . fileUri , languageCount )
450+ }
451+
452+ this . _pickedSourceFiles . add ( file . fileUri . fsPath )
453+ this . _totalSize += file . fileSizeBytes
428454 }
429455
430456 const sourceFiles = await collectFiles ( projectPaths , workspaceFolders , collectFilesOptions )
431457
432458 for ( const file of sourceFiles ) {
433459 const projectName = path . basename ( file . workspaceFolder . uri . fsPath )
434460 const zipEntryPath = this . getZipEntryPath ( projectName , file . relativeFilePath )
435- const fileExtension = path . extname ( file . fileUri . fsPath )
436461
437- if (
438- ZipConstants . knownBinaryFileExts . includes ( fileExtension ) &&
439- useCase === FeatureUseCase . TEST_GENERATION
440- ) {
462+ if ( isExcluded ( file ) ) {
441463 continue
442464 }
443465
444- if (
445- this . reachSizeLimit ( this . _totalSize , CodeWhispererConstants . CodeAnalysisScope . PROJECT ) ||
446- this . willReachSizeLimit ( this . _totalSize , file . fileSizeBytes )
447- ) {
448- throw new ProjectSizeExceededError ( )
466+ const errorToThrow = checkForError ( file )
467+ if ( errorToThrow ) {
468+ throw errorToThrow
449469 }
450470
451- if ( ZipConstants . knownBinaryFileExts . includes ( fileExtension ) ) {
452- if ( useCase === FeatureUseCase . TEST_GENERATION ) {
453- continue
454- }
455-
456- zip . writeFile ( file . fileUri . fsPath , path . dirname ( zipEntryPath ) )
471+ if ( file . isText ) {
472+ zip . writeString ( file . fileContent , zipEntryPath )
457473 } else {
458- // TODO: verify if this is needed
459- const isFileOpenAndDirty = this . isFileOpenAndDirty ( file . fileUri )
460- const fileContent = isFileOpenAndDirty ? await this . getTextContent ( file . fileUri ) : file . fileContent
461-
462- this . _totalLines += fileContent . split ( ZipConstants . newlineRegex ) . length
463-
464- this . incrementCountForLanguage ( file . fileUri , languageCount )
465- zip . writeString ( fileContent , zipEntryPath )
474+ zip . writeFile ( file . fileUri . fsPath , path . dirname ( zipEntryPath ) )
466475 }
467476
468- this . _pickedSourceFiles . add ( file . fileUri . fsPath )
469- this . _totalSize += file . fileSizeBytes
477+ computeSideEffects ( file )
470478 }
471479 }
472480
0 commit comments