Skip to content

Commit d4cd6d8

Browse files
committed
fix: add class files from local file
1 parent eddec80 commit d4cd6d8

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ZipMetadata {
3030
export const ZipConstants = {
3131
newlineRegex: /\r?\n/,
3232
gitignoreFilename: '.gitignore',
33+
knownBinaryFileExts: ['.class'],
3334
}
3435

3536
export class ZipUtil {
@@ -149,10 +150,15 @@ export class ZipUtil {
149150
this.getProjectScanPayloadSizeLimitInBytes()
150151
)
151152
for (const file of sourceFiles) {
152-
const isFileOpenAndDirty = this.isFileOpenAndDirty(file.fileUri)
153-
const fileContent = isFileOpenAndDirty ? await this.getTextContent(file.fileUri) : file.fileContent
154153
const zipEntryPath = this.getZipEntryPath(file.workspaceFolder.name, file.zipFilePath)
155-
this.processFile(zip, file.fileUri, fileContent, languageCount, zipEntryPath)
154+
155+
if (ZipConstants.knownBinaryFileExts.includes(path.extname(file.fileUri.fsPath))) {
156+
await this.processBinaryFile(zip, file.fileUri, zipEntryPath)
157+
} else {
158+
const isFileOpenAndDirty = this.isFileOpenAndDirty(file.fileUri)
159+
const fileContent = isFileOpenAndDirty ? await this.getTextContent(file.fileUri) : file.fileContent
160+
this.processTextFile(zip, file.fileUri, fileContent, languageCount, zipEntryPath)
161+
}
156162
}
157163
}
158164

@@ -161,11 +167,11 @@ export class ZipUtil {
161167
.filter((document) => document.uri.scheme === 'file')
162168
.filter((document) => vscode.workspace.getWorkspaceFolder(document.uri) === undefined)
163169
.forEach((document) =>
164-
this.processFile(zip, document.uri, document.getText(), languageCount, document.uri.fsPath)
170+
this.processTextFile(zip, document.uri, document.getText(), languageCount, document.uri.fsPath)
165171
)
166172
}
167173

168-
protected processFile(
174+
protected processTextFile(
169175
zip: admZip,
170176
uri: vscode.Uri,
171177
fileContent: string,
@@ -188,6 +194,21 @@ export class ZipUtil {
188194
zip.addFile(zipEntryPath, Buffer.from(fileContent, 'utf-8'))
189195
}
190196

197+
protected async processBinaryFile(zip: admZip, uri: vscode.Uri, zipEntryPath: string) {
198+
const fileSize = (await fs.stat(uri.fsPath)).size
199+
200+
if (
201+
this.reachSizeLimit(this._totalSize, CodeWhispererConstants.CodeAnalysisScope.PROJECT) ||
202+
this.willReachSizeLimit(this._totalSize, fileSize)
203+
) {
204+
throw new ProjectSizeExceededError()
205+
}
206+
this._pickedSourceFiles.add(uri.fsPath)
207+
this._totalSize += fileSize
208+
209+
zip.addLocalFile(uri.fsPath, path.dirname(zipEntryPath))
210+
}
211+
191212
protected incrementCountForLanguage(uri: vscode.Uri, languageCount: Map<CodewhispererLanguage, number>) {
192213
const fileExtension = path.extname(uri.fsPath).slice(1)
193214
const language = runtimeLanguageContext.getLanguageFromFileExtension(fileExtension)

0 commit comments

Comments
 (0)