@@ -50,6 +50,8 @@ export const ZipConstants = {
5050 codeDiffFilePath : 'codeDiff/code.diff' ,
5151}
5252
53+ type ZipType = 'file' | 'project'
54+
5355export class ZipUtil {
5456 protected _pickedSourceFiles : Set < string > = new Set < string > ( )
5557 protected _pickedBuildFiles : Set < string > = new Set < string > ( )
@@ -61,25 +63,18 @@ export class ZipUtil {
6163 protected _fetchedDirs : Set < string > = new Set < string > ( )
6264 protected _language : CodewhispererLanguage | undefined
6365 protected _timestamp : string = Date . now ( ) . toString ( )
64- constructor ( ) { }
65-
66- getFileScanPayloadSizeLimitInBytes ( ) : number {
67- return CodeWhispererConstants . fileScanPayloadSizeLimitBytes
68- }
69-
70- getProjectScanPayloadSizeLimitInBytes ( ) : number {
71- return CodeWhispererConstants . projectScanPayloadSizeLimitBytes
66+ protected _payloadByteLimits = {
67+ file : CodeWhispererConstants . fileScanPayloadSizeLimitBytes ,
68+ project : CodeWhispererConstants . projectScanPayloadSizeLimitBytes ,
7269 }
70+ constructor ( ) { }
7371
74- public aboveByteLimit ( size : number , scope : CodeWhispererConstants . CodeAnalysisScope ) : boolean {
75- return CodeWhispererConstants . isFileAnalysisScope ( scope )
76- ? size > this . getFileScanPayloadSizeLimitInBytes ( )
77- : size > this . getProjectScanPayloadSizeLimitInBytes ( )
72+ public aboveByteLimit ( size : number , limitType : ZipType ) : boolean {
73+ return size > this . _payloadByteLimits [ limitType ]
7874 }
7975
8076 public willReachProjectByteLimit ( current : number , adding : number ) : boolean {
81- const willReachLimit = current + adding > this . getProjectScanPayloadSizeLimitInBytes ( )
82- return willReachLimit
77+ return this . aboveByteLimit ( current + adding , 'project' )
8378 }
8479
8580 protected async zipFile ( uri : vscode . Uri | undefined , scope : CodeWhispererConstants . CodeAnalysisScope ) {
@@ -112,7 +107,7 @@ export class ZipUtil {
112107 this . _totalSize += ( await fs . stat ( uri . fsPath ) ) . size
113108 this . _totalLines += content . split ( ZipConstants . newlineRegex ) . length
114109
115- if ( this . aboveByteLimit ( this . _totalSize , scope ) ) {
110+ if ( this . aboveByteLimit ( this . _totalSize , 'file' ) ) {
116111 throw new FileSizeExceededError ( )
117112 }
118113 const zipFilePath = this . getZipDirPath ( FeatureUseCase . CODE_SCAN ) + CodeWhispererConstants . codeScanZipExt
@@ -242,7 +237,7 @@ export class ZipUtil {
242237 )
243238 : vscode . workspace . workspaceFolders ) as CurrentWsFolders ,
244239 {
245- maxTotalSizeBytes : this . getProjectScanPayloadSizeLimitInBytes ( ) ,
240+ maxTotalSizeBytes : this . _payloadByteLimits [ 'project' ] ,
246241 excludePatterns :
247242 useCase === FeatureUseCase . TEST_GENERATION
248243 ? [ ...CodeWhispererConstants . testGenExcludePatterns , ...defaultExcludePatterns ]
@@ -305,7 +300,7 @@ export class ZipUtil {
305300 const fileSize = Buffer . from ( fileContent ) . length
306301
307302 if (
308- this . aboveByteLimit ( this . _totalSize , CodeWhispererConstants . CodeAnalysisScope . PROJECT ) ||
303+ this . aboveByteLimit ( this . _totalSize , 'project' ) ||
309304 this . willReachProjectByteLimit ( this . _totalSize , fileSize )
310305 ) {
311306 throw new ProjectSizeExceededError ( )
@@ -322,7 +317,7 @@ export class ZipUtil {
322317 const fileSize = ( await fs . stat ( uri . fsPath ) ) . size
323318
324319 if (
325- this . aboveByteLimit ( this . _totalSize , CodeWhispererConstants . CodeAnalysisScope . PROJECT ) ||
320+ this . aboveByteLimit ( this . _totalSize , 'project' ) ||
326321 this . willReachProjectByteLimit ( this . _totalSize , fileSize )
327322 ) {
328323 throw new ProjectSizeExceededError ( )
0 commit comments