Skip to content

Commit d838201

Browse files
committed
refactor: inline processing functions
1 parent 1c4dffd commit d838201

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

packages/core/src/codewhisperer/util/zipUtil.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,36 @@ export class ZipUtil {
434434
const zipEntryPath = this.getZipEntryPath(projectName, file.relativeFilePath)
435435
const fileExtension = path.extname(file.fileUri.fsPath)
436436

437+
if (
438+
ZipConstants.knownBinaryFileExts.includes(fileExtension) &&
439+
useCase === FeatureUseCase.TEST_GENERATION
440+
) {
441+
continue
442+
}
443+
444+
if (
445+
this.reachSizeLimit(this._totalSize, CodeWhispererConstants.CodeAnalysisScope.PROJECT) ||
446+
this.willReachSizeLimit(this._totalSize, file.fileSizeBytes)
447+
) {
448+
throw new ProjectSizeExceededError()
449+
}
450+
437451
if (ZipConstants.knownBinaryFileExts.includes(fileExtension)) {
438-
if (useCase === FeatureUseCase.TEST_GENERATION) {
439-
continue
440-
}
441-
await this.processBinaryFile(zip, file.fileUri, zipEntryPath)
452+
zip.writeFile(file.fileUri.fsPath, path.dirname(zipEntryPath))
442453
} else {
443-
const isFileOpenAndDirty = this.isFileOpenAndDirty(file.fileUri)
444-
const fileContent = isFileOpenAndDirty ? await this.getTextContent(file.fileUri) : file.fileContent
445-
this.processTextFile(zip, file.fileUri, fileContent, languageCount, zipEntryPath)
454+
// TODO: verify if this is needed
455+
// const isFileOpenAndDirty = this.isFileOpenAndDirty(file.fileUri)
456+
// const fileContent = isFileOpenAndDirty ? await this.getTextContent(file.fileUri) : file.fileContent
457+
// const fileSize = Buffer.from(fileContent).length
458+
459+
this._totalLines += file.fileContent.split(ZipConstants.newlineRegex).length
460+
461+
this.incrementCountForLanguage(file.fileUri, languageCount)
462+
zip.writeString(file.fileContent, zipEntryPath)
446463
}
464+
465+
this._pickedSourceFiles.add(file.fileUri.fsPath)
466+
this._totalSize += file.fileSizeBytes
447467
}
448468
}
449469

@@ -499,21 +519,6 @@ export class ZipUtil {
499519
zip.writeString(fileContent, zipEntryPath)
500520
}
501521

502-
protected async processBinaryFile(zip: ZipStream, uri: vscode.Uri, zipEntryPath: string) {
503-
const fileSize = (await fs.stat(uri.fsPath)).size
504-
505-
if (
506-
this.reachSizeLimit(this._totalSize, CodeWhispererConstants.CodeAnalysisScope.PROJECT) ||
507-
this.willReachSizeLimit(this._totalSize, fileSize)
508-
) {
509-
throw new ProjectSizeExceededError()
510-
}
511-
this._pickedSourceFiles.add(uri.fsPath)
512-
this._totalSize += fileSize
513-
514-
zip.writeFile(uri.fsPath, path.dirname(zipEntryPath))
515-
}
516-
517522
protected incrementCountForLanguage(uri: vscode.Uri, languageCount: Map<CodewhispererLanguage, number>) {
518523
const fileExtension = path.extname(uri.fsPath).slice(1)
519524
const language = runtimeLanguageContext.getLanguageFromFileExtension(fileExtension)

0 commit comments

Comments
 (0)