summaryrefslogtreecommitdiff
path: root/core/lib_syntax.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 01:59:49 -0300
committerGabriel Schneider <[email protected]>2026-11-21 02:00:21 -0300
commitee5b6aa3ef0bf398c5381498af40fa93d20cf0b3 (patch)
tree808bb75b174c0835e1bfedff9d01f15ba273c629 /core/lib_syntax.zig
parent44b4d81cd1ba49a035e66699416639b46723c872 (diff)
downloadpardes-ee5b6aa3ef0bf398c5381498af40fa93d20cf0b3.tar.gz
pardes-ee5b6aa3ef0bf398c5381498af40fa93d20cf0b3.zip
library: the patch view without the editor: pardes-syntax exports hunks.format as `formatPatch` with its `PatchCtx` (an arena; optional `source`, `declarations` (`PatchCtx.parsed`), `colors` (`PatchCtx.languages`: highlightDiff's), `width`; their defaults no file, no declaration, no colour, code points) and its rows, `Patch`, `PatchRow` (kind other, meta, hunk, declaration, context, added, removed; the path; the line it points at; the old and the new number, each null where that side has none; location_end, code_start; a style byte a byte; no_newline, the `\\ No newline` the editor folds into the line above); format no longer makes locations.Row (it needs no editor type: the file's first half imports nothing of root.zig's) and the editor's openDiff maps its rows onto a pane's (`paneResult`, one pass, the rows as before, so the +Diff is unchanged), handing in its own source, declarations cache, colours and display width (File.displayWidth, the one use of vaxis: `width` replaces Ctx.tab); with no `colors` the formatter calls nothing of tree-sitter (the grounds and the words a changed line changed are text alone); inferEdits' 8 MiB scratch is made once a format call, not once a run of changed lines (a browser's wasm memory took 8 MiB a run, never given back in the call); test/consumer: a C diff with no file (numbered by the diff, under git's `@@` words, `foo`/`bar` emphasised, coloured as C) and with main.c handed in (its declaration from the parse above `main.c:3 *`), and in a build with no grammar (none.zig: rows, grounds and the changed `*`, no colour; a file handed in places the hunk and makes no declaration up)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/lib_syntax.zig')
-rw-r--r--core/lib_syntax.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/lib_syntax.zig b/core/lib_syntax.zig
index f4f85820..0bb3f510 100644
--- a/core/lib_syntax.zig
+++ b/core/lib_syntax.zig
@@ -13,6 +13,7 @@
const syntax = @import("syntax.zig");
const colors = @import("colors.zig");
const modal = @import("modal.zig");
+const hunks = @import("hunks.zig");
/// Every grammar pardes knows (`all`), by name or alias (`byName`) and by
/// path (`byPath`). The build's `grammars` option says which of them are
@@ -70,6 +71,22 @@ pub const ground_emph = syntax.ground_emph;
pub const ground_line = syntax.ground_line;
pub const Grounds = colors.Grounds;
+/// A unified diff stacked as pardes's patch view (its +Diff) shows it:
+/// `formatPatch` gives a `Patch`, its text and a `PatchRow` a line: a
+/// hunk's `path:line`, the declarations it stands in (or git's function
+/// line), its lines with both their numbers, each byte's style (a `Syn`
+/// when `colors` are given, the grounds, the words a changed line changed).
+/// What it takes of the program is a `PatchCtx`: an arena, and optionally
+/// the files the diff names (`source`, a `PatchSource`), their declarations
+/// (`PatchCtx.parsed`), the colours (`PatchCtx.languages`, highlightDiff's)
+/// and a text's width; with none of them it names no grammar and no
+/// tree-sitter.
+pub const formatPatch = hunks.format;
+pub const PatchCtx = hunks.Ctx;
+pub const PatchSource = hunks.Source;
+pub const Patch = hunks.Patch;
+pub const PatchRow = hunks.Row;
+
/// The tree-sitter bindings a tree is read through: `tree.rootNode()`, and
/// a node's `kind()`, `startByte()`, `endByte()`, `child(i)`, `parent()`.
pub const ts = syntax.ts;