@@ -66,6 +66,7 @@ interface FileSizeDetails {
6666 skippedSize : number
6767}
6868const MAX_UNCOMPRESSED_SRC_SIZE_BYTES = 2 * 1024 * 1024 * 1024 // 2 GB
69+ const MAX_FILES = 500_000
6970
7071export class ArtifactManager {
7172 private workspace : Workspace
@@ -175,7 +176,8 @@ export class ArtifactManager {
175176 }
176177
177178 if ( isDirectory ( filePath ) ) {
178- const files = await glob ( [ '**/*' ] , {
179+ let fileCount = 0
180+ const filesStream = glob . stream ( [ '**/*' ] , {
179181 cwd : filePath ,
180182 dot : false ,
181183 ignore : IGNORE_DEPENDENCY_PATTERNS ,
@@ -184,7 +186,11 @@ export class ArtifactManager {
184186 onlyFiles : true ,
185187 } )
186188
187- for ( const relativePath of files ) {
189+ for await ( const entry of filesStream ) {
190+ if ( fileCount >= MAX_FILES ) {
191+ break
192+ }
193+ const relativePath = entry . toString ( )
188194 try {
189195 const fullPath = resolveSymlink ( path . join ( filePath , relativePath ) )
190196 const fileMetadata = await this . createFileMetadata (
@@ -197,6 +203,7 @@ export class ArtifactManager {
197203 } catch ( error ) {
198204 this . logging . warn ( `Error processing file ${ relativePath } : ${ error } ` )
199205 }
206+ fileCount ++
200207 }
201208 } else {
202209 const workspaceUri = URI . parse ( currentWorkspace . uri )
@@ -359,7 +366,8 @@ export class ArtifactManager {
359366 ) : Promise < Map < CodewhispererLanguage , FileMetadata [ ] > > {
360367 const filesByLanguage = new Map < CodewhispererLanguage , FileMetadata [ ] > ( )
361368
362- const files = await glob ( [ '**/*' ] , {
369+ const files = [ ]
370+ const filesStream = glob . stream ( [ '**/*' ] , {
363371 cwd : directoryPath ,
364372 dot : false ,
365373 ignore : IGNORE_PATTERNS ,
@@ -368,11 +376,26 @@ export class ArtifactManager {
368376 onlyFiles : true ,
369377 } )
370378
379+ for await ( const entry of filesStream ) {
380+ if ( files . length >= MAX_FILES ) {
381+ break
382+ }
383+ files . push ( entry . toString ( ) )
384+ }
385+
386+ const hasJavaFile = files . some ( file => file . endsWith ( '.java' ) )
387+
371388 for ( const relativePath of files ) {
372389 const fullPath = path . join ( directoryPath , relativePath )
373- const language = getCodeWhispererLanguageIdFromPath ( fullPath )
374-
375- if ( ! language || ! SUPPORTED_WORKSPACE_CONTEXT_LANGUAGES . includes ( language ) ) {
390+ const isJavaProjectFile = isJavaProjectFileFromPath ( fullPath )
391+ const language = isJavaProjectFileFromPath ( fullPath ) ? 'java' : getCodeWhispererLanguageIdFromPath ( fullPath )
392+
393+ if (
394+ ! language ||
395+ ! SUPPORTED_WORKSPACE_CONTEXT_LANGUAGES . includes ( language ) ||
396+ // skip processing the java project file if there's no java source file
397+ ( ! hasJavaFile && isJavaProjectFile )
398+ ) {
376399 continue
377400 }
378401
@@ -631,7 +654,7 @@ export class ArtifactManager {
631654 files : FileMetadata [ ]
632655 ) : Promise < FileMetadata [ ] > {
633656 const workspacePath = URI . parse ( workspaceFolder . uri ) . path
634- const hasJavaFiles = files . some ( file => file . language === 'java' && file . relativePath . endsWith ( 'java' ) )
657+ const hasJavaFiles = files . some ( file => file . language === 'java' && file . relativePath . endsWith ( '. java' ) )
635658
636659 if ( ! hasJavaFiles ) {
637660 return files
0 commit comments