code/editor/patch-parse
import { … } from 'zidane-ui/code/editor'ui/src/code/editor/patch-parse.ts
Functions#
createPatchParserFunction#
A parser that runs parseWorkingTree in a worker (one, made on first use), so a burst of re-reads on a
repository with a large diff never parses megabytes on the main thread. Without createWorker, or once the
worker failed (a load error, a crash), it parses on this thread: what a dead worker held is settled there.
The worker is an app's module that answers each ParseRequest with parseWorkingTree(request).
function createPatchParser(createWorker: (() => Worker) | null): PatchParserParameters
| Name | Type | Description |
|---|---|---|
| createWorker | (() => Worker) | null | Makes the worker; |
Returns
hashTextFunction#
FNV-1a, 32 bits, as hex: fast, and collisions only cost a reused parse of the same path.
function hashText(text: string): stringParameters
| Name | Type | Description |
|---|---|---|
| text | string | The text to hash. |
Returns
stringparseFilePatchFunction#
Parses a one-file patch (a file's working-tree diff); undefined when it holds no file.
function parseFilePatch(patch: string, cacheKey: string): FileDiffMetadata | undefinedParameters
| Name | Type | Description |
|---|---|---|
| patch | string | A unified patch of one file. |
| cacheKey | string | Prefix of pierre's cache keys for it. |
Returns
FileDiffMetadata | undefinedparseSectionFunction#
Parse one file section; null when pierre can't read it (that file is left out, the others still show).
function parseSection(key: string, text: string): FileDiffMetadata | nullParameters
| Name | Type | Description |
|---|---|---|
| key | string | The section's content key (pierre's cache key). |
| text | string | The section. |
Returns
FileDiffMetadata | nullparseWorkingTreeFunction#
Parses the sections of a patch the caller doesn't hold yet. What a parser worker runs on each message.
function parseWorkingTree(req: ParseRequest): ParseResponseParameters
| Name | Type | Description |
|---|---|---|
| req | ParseRequest | The patch and the keys already held. |
Returns
sectionKeysFunction#
The file sections of a patch with their content keys.
function sectionKeys(patch: string): SectionKey[]Parameters
| Name | Type | Description |
|---|---|---|
| patch | string | A unified patch of any number of files. |
Returns
splitPatchFunction#
Split a multi-file patch at its diff --git headers (text before the first one is dropped).
function splitPatch(patch: string): string[]Parameters
| Name | Type | Description |
|---|---|---|
| patch | string | A unified patch of any number of files. |
Returns
string[]Interfaces#
ParseRequestInterface#
What a parser worker receives.
interface ParseRequestProperties
| Name | Type | Description |
|---|---|---|
| id | number | Matches the response to the request. |
| known | string[] | Sections the caller already holds parsed: sent back as keys only. |
| patch | string | The working-tree patch. |
ParseResponseInterface#
What a parser worker answers.
interface ParseResponseProperties
| Name | Type | Description |
|---|---|---|
| files | { file?: FileDiffMetadata | null; key: string }[] | In patch order: a key the caller knows, or a freshly parsed file (null when unreadable). |
| id | number | The request's id. |
SectionKeyInterface#
One file section of a patch, keyed by its content.
interface SectionKeyProperties
| Name | Type | Description |
|---|---|---|
| key | string | Content hash plus the section's index among equal hashes (two identical sections stay distinct). |
| text | string | The section's text. |
Types#
PatchParserType#
Parses a working-tree patch, the sections it doesn't hold yet only.
type PatchParser = (patch: string, known: string[]) => Promise<ParseResponse>