Skip to content

Commit 605fc87

Browse files
committed
feat: check if file is binary when collecting
1 parent d60af22 commit 605fc87

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import fs from '../fs/fs'
2020
import { ChildProcess } from './processUtils'
2121
import { isWin } from '../vscode/env'
2222
import { maxRepoSizeBytes } from '../../amazonqFeatureDev/constants'
23+
import { ZipConstants } from '../../codewhisperer/util/zipUtil'
2324

2425
type GitIgnoreRelativeAcceptor = {
2526
folderPath: string
@@ -335,6 +336,7 @@ export type CollectFilesResultItem = {
335336
fileUri: vscode.Uri
336337
fileContent: string
337338
fileSizeBytes: number
339+
isText: boolean
338340
zipFilePath: string
339341
}
340342
export type CollectFilesFilter = (relativePath: string) => boolean // returns true if file should be filtered out
@@ -421,12 +423,13 @@ export async function collectFiles(
421423
continue
422424
}
423425

424-
const result = {
426+
const result: Omit<CollectFilesResultItem, 'fileContent'> = {
425427
workspaceFolder: relativePath.workspaceFolder,
426428
relativeFilePath: relativePath.relativePath,
427429
fileUri: file,
428430
fileSizeBytes: fileStat.size,
429431
zipFilePath: prefixWithFolderPrefix(relativePath.workspaceFolder, relativePath.relativePath),
432+
isText: !ZipConstants.knownBinaryFileExts.includes(path.extname(file.fsPath)),
430433
}
431434
if (includeContent) {
432435
const content = await readFile(file)

packages/core/src/testInteg/shared/utilities/workspaceUtils.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,48 +267,56 @@ describe('workspaceUtils', () => {
267267
relativeFilePath: '.gitignore',
268268
fileContent: gitignoreContent,
269269
fileSizeBytes: 162,
270+
isText: true,
270271
},
271272
{
272273
workspaceFolder,
273274
relativeFilePath: 'file1',
274275
fileContent: 'test content',
275276
fileSizeBytes: 12,
277+
isText: true,
276278
},
277279
{
278280
workspaceFolder,
279281
relativeFilePath: 'file3',
280282
fileContent: 'test content',
281283
fileSizeBytes: 12,
284+
isText: true,
282285
},
283286
{
284287
workspaceFolder,
285288
relativeFilePath: 'range_file9',
286289
fileContent: 'test content',
287290
fileSizeBytes: 12,
291+
isText: true,
288292
},
289293
{
290294
workspaceFolder,
291295
relativeFilePath: path.join('src', '.gitignore'),
292296
fileContent: gitignore2,
293297
fileSizeBytes: 8,
298+
isText: true,
294299
},
295300
{
296301
workspaceFolder,
297302
relativeFilePath: path.join('src', 'folder2', 'a.js'),
298303
fileContent: fileContent,
299304
fileSizeBytes: 12,
305+
isText: true,
300306
},
301307
{
302308
workspaceFolder,
303309
relativeFilePath: path.join('src', 'folder3', '.gitignore'),
304310
fileContent: gitignore3,
305311
fileSizeBytes: 42,
312+
isText: true,
306313
},
307314
{
308315
workspaceFolder,
309316
relativeFilePath: path.join('src', 'folder3', 'negate_test1'),
310317
fileContent: fileContent,
311318
fileSizeBytes: 12,
319+
isText: true,
312320
},
313321
] satisfies typeof result,
314322
result
@@ -517,11 +525,13 @@ describe('workspaceUtils', () => {
517525
workspaceFolder,
518526
relativeFilePath: path.join('src', 'folder2', 'a.js'),
519527
fileSizeBytes: 12,
528+
isText: true,
520529
},
521530
{
522531
workspaceFolder,
523532
relativeFilePath: path.join('src', 'folder2', 'b.cs'),
524533
fileSizeBytes: 12,
534+
isText: true,
525535
},
526536
] satisfies typeof result,
527537
result
@@ -548,11 +558,13 @@ describe('workspaceUtils', () => {
548558
workspaceFolder,
549559
relativeFilePath: 'a.js',
550560
fileSizeBytes: 14,
561+
isText: true,
551562
},
552563
{
553564
workspaceFolder,
554565
relativeFilePath: 'b.java',
555566
fileSizeBytes: 14,
567+
isText: true,
556568
},
557569
] satisfies typeof result,
558570
result
@@ -579,11 +591,13 @@ describe('workspaceUtils', () => {
579591
workspaceFolder,
580592
relativeFilePath: 'top.java',
581593
fileSizeBytes: 14,
594+
isText: true,
582595
},
583596
{
584597
workspaceFolder,
585598
relativeFilePath: 'top.js',
586599
fileSizeBytes: 14,
600+
isText: true,
587601
},
588602
] satisfies typeof result,
589603
result

0 commit comments

Comments
 (0)