mirror of
https://github.com/stablyai/orca.git
synced 2026-10-07 08:02:21 +00:00
Deferral keyed "no line counts" off the untracked area, which both prompted ordinary untracked binaries and silently auto-loaded every tracked row when a status pass skipped counting (entry cap hit, numstat failed) — the freeze case the deferral exists for. Decide from the path instead: rows that render as a preview or a binary stub stay automatic, everything Monaco would open as text defers. Also give all three combined-diff virtualizers one shared row estimate, so the PR-review viewers stop estimating a deferred/in-flight large row at 88px while DiffSectionItem renders it at 188px, and drop the dead isLoadOnDemand parameter that estimate covered.
91 lines
1.8 KiB
TypeScript
91 lines
1.8 KiB
TypeScript
import { IMAGE_FILE_EXTENSIONS } from './image-file-extensions'
|
|
|
|
// SVG is an image format that editors open as source text, so it stays out of
|
|
// the binary set even though it lives in IMAGE_FILE_EXTENSIONS.
|
|
const TEXT_IMAGE_EXTENSIONS = new Set(['.svg'])
|
|
|
|
const NON_IMAGE_BINARY_EXTENSIONS = [
|
|
// Archives
|
|
'.7z',
|
|
'.bz2',
|
|
'.gz',
|
|
'.jar',
|
|
'.rar',
|
|
'.tar',
|
|
'.tgz',
|
|
'.war',
|
|
'.xz',
|
|
'.zip',
|
|
'.zst',
|
|
// Audio and video
|
|
'.aac',
|
|
'.avi',
|
|
'.flac',
|
|
'.m4a',
|
|
'.mkv',
|
|
'.mov',
|
|
'.mp3',
|
|
'.mp4',
|
|
'.ogg',
|
|
'.wav',
|
|
'.webm',
|
|
// Documents
|
|
'.doc',
|
|
'.docx',
|
|
'.pdf',
|
|
'.ppt',
|
|
'.pptx',
|
|
'.xls',
|
|
'.xlsx',
|
|
// Fonts
|
|
'.eot',
|
|
'.otf',
|
|
'.ttc',
|
|
'.ttf',
|
|
'.woff',
|
|
'.woff2',
|
|
// Compiled artifacts and datastores
|
|
'.a',
|
|
'.bin',
|
|
'.class',
|
|
'.dll',
|
|
'.dylib',
|
|
'.exe',
|
|
'.idx',
|
|
'.lockb',
|
|
'.node',
|
|
'.o',
|
|
'.pack',
|
|
'.pyc',
|
|
'.pyd',
|
|
'.so',
|
|
'.sqlite',
|
|
'.sqlite3',
|
|
'.wasm'
|
|
]
|
|
|
|
export const BINARY_FILE_EXTENSIONS: readonly string[] = Object.freeze([
|
|
...IMAGE_FILE_EXTENSIONS.filter((extension) => !TEXT_IMAGE_EXTENSIONS.has(extension)),
|
|
...NON_IMAGE_BINARY_EXTENSIONS
|
|
])
|
|
|
|
const BINARY_FILE_EXTENSION_SET = new Set(BINARY_FILE_EXTENSIONS)
|
|
|
|
/**
|
|
* Extension-only guess at "this file is not text". Content-based detection
|
|
* lives in `isBinaryBuffer`; use this only where the bytes are unavailable.
|
|
*/
|
|
export function hasBinaryFileExtension(filePath: string | undefined): boolean {
|
|
if (filePath === undefined) {
|
|
return false
|
|
}
|
|
const lowerPath = filePath.toLowerCase()
|
|
const dotIndex = lowerPath.lastIndexOf('.')
|
|
const separatorIndex = Math.max(lowerPath.lastIndexOf('/'), lowerPath.lastIndexOf('\\'))
|
|
// A leading dot is a dotfile (.gitignore), not an extension.
|
|
if (dotIndex <= separatorIndex + 1) {
|
|
return false
|
|
}
|
|
return BINARY_FILE_EXTENSION_SET.has(lowerPath.slice(dotIndex))
|
|
}
|