diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 17:50:13 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 17:58:08 -0300 |
| commit | 4eb608b0c1f231005237b0f57283d22bfccee0a9 (patch) | |
| tree | a04992918515c2dbdea0837c3de5d854ac65d5bf /core/hunks.zig | |
| parent | fcc08ec6ceb9af11aeda8489cef0d4085878ef48 (diff) | |
| download | pardes-4eb608b0c1f231005237b0f57283d22bfccee0a9.tar.gz pardes-4eb608b0c1f231005237b0f57283d22bfccee0a9.zip | |
a file's name in a row is written as git writes an unusual one, and read back so: a newline in a name no longer makes a row of its own: the Grep worker wrote `path:line:col-end code` with the name as it is (core/Stream.zig `row`, and Find's `file`), so a file named `a\nb:1:1` holding a hit made two rows, `a` (no place, passed over) and a hit in a file `b` at line 1, which a crafted name can point anywhere with any text (the test below on the base: the one hit's name `b`); the query pane's rows the same (a name with a newline was two lines of the pane's text over one row's metadata); and a name with a `:` and digits in it read as another file at a line (`a:5:b.txt:3`); THE RULE, one for every row that names a file: git's quote_c_style, `look.quoted`: a name holding a control byte, a `"`, a `\` or a `:` is written in double quotes with `\n \t \r \" \\` and `\ooo` for the other control bytes, any other name as it is; WRITTEN by the worker (Stream `row`, `file`), the query pane's rows (Query: a Grep's, a language server's, a pane's places: the name `lookPath` gives, quoted), the patch view's labels (hunks.zig `flush`); READ by `look.parsePathLine`, which takes a `"`-led word whole to its closing quote as the path (its `:` its own; the place after it as ever), Query `take` (the name unquoted, `look.unquoted`, into the Found it opens) and Find's rows (the name a row shows opens the file it names); a B3 on a quoted row whose name has an escape finds the escaped text and misses (no file has it): a miss, never another file; the patch view's names come from the diff, where git quotes the same way (diff.zig `cutPath` keeps the inside), and Find's rows show the name as the worker wrote it; tests: core/Stream.zig "a file named `a\nb:1:1` is one Grep row and one Find name, its own, for the walk and rg; a row is a line" (fails on the base), core/look.zig "a file's name written as a row writes it reads back whole: ..."; core-test Debug 953/1119 (166 skipped)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/hunks.zig')
| -rw-r--r-- | core/hunks.zig | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/hunks.zig b/core/hunks.zig index d8c5e2de..bdebc34d 100644 --- a/core/hunks.zig +++ b/core/hunks.zig @@ -15,6 +15,7 @@ const std = @import("std"); const diff = @import("diff.zig"); const syntax = @import("syntax.zig"); const locations = @import("locations.zig"); +const look = @import("look.zig"); const pardes = @import("root.zig"); const Pardes = pardes.Pardes; @@ -385,7 +386,7 @@ fn flush(ctx: *const Ctx, out: *Out, hunk: *Hunk, memo: *SourceMemo, scratch: *[ var row = declaration.start_line; while (row <= declaration.header_end_line and row < start_row) : (row += 1) { if (row == declaration.start_line and ctx.tslocations) { - const label = try std.fmt.allocPrint(arena, "{s}:{d}", .{ shown, row + 1 }); + const label = try std.fmt.allocPrint(arena, "{f}:{d}", .{ look.quoted(shown), row + 1 }); try out.row(arena, label, .{ .kind = .declaration, .path = shown, .line = row + 1, .location_end = label.len, .code_start = label.len }); } // A blank where a hunk line has its marker: the code aligns. @@ -396,7 +397,8 @@ fn flush(ctx: *const Ctx, out: *Out, hunk: *Hunk, memo: *SourceMemo, scratch: *[ // The hunk's label: a step for n and N, and a look's place. const line_no = change_row + 1; var label: std.Io.Writer.Allocating = .init(arena); - try label.writer.print("{s}:{d}", .{ shown, line_no }); + // The name as a row writes it (look.quoted): a `:` in it never splits it. + try label.writer.print("{f}:{d}", .{ look.quoted(shown), line_no }); const location_end = label.written().len; if (depth > 0) { try label.writer.writeByte(' '); |
