Skip to content

Commit 98c7b96

Browse files
committed
refactor: move file opening util outside zipUtil
1 parent 776dffb commit 98c7b96

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { ProjectZipError } from '../../amazonqTest/error'
3030
import { removeAnsi } from '../../shared/utilities/textUtilities'
3131
import { normalize } from '../../shared/utilities/pathUtils'
3232
import { ZipStream } from '../../shared/utilities/zipStream'
33+
import { getTextContent } from '../../shared/utilities/vsCodeUtils'
3334

3435
export interface ZipMetadata {
3536
rootDir: string
@@ -77,12 +78,6 @@ export class ZipUtil {
7778
return CodeWhispererConstants.projectScanPayloadSizeLimitBytes
7879
}
7980

80-
protected async getTextContent(uri: vscode.Uri) {
81-
const document = await vscode.workspace.openTextDocument(uri)
82-
const content = document.getText()
83-
return content
84-
}
85-
8681
public reachSizeLimit(size: number, scope: CodeWhispererConstants.CodeAnalysisScope): boolean {
8782
if (
8883
scope === CodeWhispererConstants.CodeAnalysisScope.FILE_AUTO ||
@@ -105,7 +100,7 @@ export class ZipUtil {
105100
}
106101
const zip = new ZipStream()
107102

108-
const content = await this.getTextContent(uri)
103+
const content = await getTextContent(uri)
109104

110105
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri)
111106
if (workspaceFolder) {
@@ -431,7 +426,7 @@ export class ZipUtil {
431426
await this.processBinaryFile(zip, file.fileUri, zipEntryPath)
432427
} else {
433428
const isFileOpenAndDirty = this.isFileOpenAndDirty(file.fileUri)
434-
const fileContent = isFileOpenAndDirty ? await this.getTextContent(file.fileUri) : file.fileContent
429+
const fileContent = isFileOpenAndDirty ? await getTextContent(file.fileUri) : file.fileContent
435430
this.processTextFile(zip, file.fileUri, fileContent, languageCount, zipEntryPath)
436431
}
437432
}

packages/core/src/shared/utilities/vsCodeUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,9 @@ export function subscribeOnce<T>(event: vscode.Event<T>): vscode.Event<T> {
254254
return result
255255
}
256256
}
257+
258+
export async function getTextContent(uri: vscode.Uri) {
259+
const document = await vscode.workspace.openTextDocument(uri)
260+
const content = document.getText()
261+
return content
262+
}

0 commit comments

Comments
 (0)