summaryrefslogtreecommitdiff
path: root/src/File.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/File.zig')
-rw-r--r--src/File.zig82
1 files changed, 60 insertions, 22 deletions
diff --git a/src/File.zig b/src/File.zig
index 31392ebd..c42e39ec 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -253,6 +253,8 @@ fn dumpLocationRows(arena: std.mem.Allocator, rows: []const locations.Row) ![]co
for (rows, saved) |row, *out| out.* = .{
.kind = @enumFromInt(@intFromEnum(row.kind)),
.declaration = row.declaration,
+ .mark_occurrence = row.mark_occurrence,
+ .source_column = row.source_column,
.path = row.path,
.line = row.at.line,
.col = row.at.col,
@@ -271,6 +273,10 @@ fn sameSavedLocation(a: dump.LocationRow, b: dump.LocationRow) bool {
}
fn restoreLocationRows(gpa: std.mem.Allocator, content: []const u8, saved: []const dump.LocationRow) ![]locations.Row {
+ return restoreOutputLocationRows(gpa, content, saved, false);
+}
+
+fn restoreOutputLocationRows(gpa: std.mem.Allocator, content: []const u8, saved: []const dump.LocationRow, callstack: bool) ![]locations.Row {
if (saved.len == 0) return &.{};
if (saved.len > std.mem.count(u8, content, "\n") + 1) return error.InvalidLocationRows;
const rows = try gpa.alloc(locations.Row, saved.len);
@@ -286,29 +292,44 @@ fn restoreLocationRows(gpa: std.mem.Allocator, content: []const u8, saved: []con
var previous_line: []const u8 = "";
for (saved, rows, 0..) |row, *out, index| {
const line = lines.next() orelse return error.InvalidLocationRows;
- if (row.path.len == 0 or row.path.len >= 4096 or
+ if ((!callstack and row.path.len == 0) or row.path.len >= 4096 or
row.location_end > row.code_start or row.code_start > line.len or
(row.kind == .match and row.location_end == 0) or
(row.declaration and row.kind != .context) or
row.line > std.math.maxInt(i32) or row.col > std.math.maxInt(i32) or
row.end_line > std.math.maxInt(i32) or row.end_col > std.math.maxInt(i32))
return error.InvalidLocationRows;
- const inline_row = row.code_start > row.location_end and row.code_start > 0 and line[row.code_start - 1] == '\t';
- const address_row = !inline_row and row.location_end > 0 and row.code_start == line.len;
- const source_row = row.location_end == 0 and row.code_start == 0;
- if (!inline_row and !address_row and !source_row) return error.InvalidLocationRows;
- if (row.kind == .preview) {
- if (!source_row or index == 0) return error.InvalidLocationRows;
- const previous = saved[index - 1];
- if (previous.kind != .match or previous.location_end == 0 or previous.code_start != previous_line.len or previous_line[previous_line.len - 1] == '\t' or
- !sameSavedLocation(previous, row)) return error.InvalidLocationRows;
- }
- if (address_row) {
- if (index + 1 >= saved.len) return error.InvalidLocationRows;
- const following = saved[index + 1];
- const expected: @TypeOf(row.kind) = if (row.kind == .match) .preview else .context;
- if (following.kind != expected or following.code_start != 0 or following.location_end != 0 or
- following.declaration != row.declaration or !sameSavedLocation(row, following)) return error.InvalidLocationRows;
+ if (callstack) {
+ if (row.location_end > 0) {
+ const prefix = locations.treePrefix(line);
+ const parsed = locations.parseRaw(line[prefix.end..]);
+ if (row.kind != .match or parsed.at.line == 0 or
+ !std.mem.eql(u8, parsed.path, row.path) or
+ parsed.at.line != row.line or parsed.at.col != row.col or
+ parsed.at.end_line != row.end_line or parsed.at.end_col != row.end_col or
+ prefix.end + parsed.end != row.location_end or
+ prefix.end + parsed.code_start != row.code_start) return error.InvalidLocationRows;
+ } else if (row.kind == .preview) {
+ if (index == 0 or saved[index - 1].kind != .match or !sameSavedLocation(saved[index - 1], row)) return error.InvalidLocationRows;
+ } else if (row.kind != .context or (row.path.len == 0 and (row.line != 0 or row.code_start != line.len))) return error.InvalidLocationRows;
+ } else {
+ const inline_row = row.code_start > row.location_end and row.code_start > 0 and line[row.code_start - 1] == '\t';
+ const address_row = !inline_row and row.location_end > 0 and row.code_start == line.len;
+ const source_row = row.location_end == 0 and row.code_start == 0;
+ if (!inline_row and !address_row and !source_row) return error.InvalidLocationRows;
+ if (row.kind == .preview) {
+ if (!source_row or index == 0) return error.InvalidLocationRows;
+ const previous = saved[index - 1];
+ if (previous.kind != .match or previous.location_end == 0 or previous.code_start != previous_line.len or previous_line[previous_line.len - 1] == '\t' or
+ !sameSavedLocation(previous, row)) return error.InvalidLocationRows;
+ }
+ if (address_row) {
+ if (index + 1 >= saved.len) return error.InvalidLocationRows;
+ const following = saved[index + 1];
+ const expected: @TypeOf(row.kind) = if (row.kind == .match) .preview else .context;
+ if (following.kind != expected or following.code_start != 0 or following.location_end != 0 or
+ following.declaration != row.declaration or !sameSavedLocation(row, following)) return error.InvalidLocationRows;
+ }
}
const code_len = line.len - row.code_start;
if (row.colors_b64.len > std.base64.standard.Encoder.calcSize(code_len)) return error.InvalidLocationRows;
@@ -320,6 +341,8 @@ fn restoreLocationRows(gpa: std.mem.Allocator, content: []const u8, saved: []con
out.* = .{
.kind = @enumFromInt(@intFromEnum(row.kind)),
.declaration = row.declaration,
+ .mark_occurrence = row.mark_occurrence,
+ .source_column = row.source_column,
.path = path,
.at = .{ .line = row.line, .col = row.col, .end_line = row.end_line, .end_col = row.end_col },
.location_end = row.location_end,
@@ -992,7 +1015,8 @@ pub fn restore(p: *Pardes, id: usize, src: dump.Pane) !*Pane {
} else null;
if (saved.location_rows.len != 0 and output == null) return error.InvalidLocationRows;
- const location_rows = try restoreLocationRows(p.gpa, content, saved.location_rows);
+ const is_callstack = if (output) |state| std.meta.eql(state.from, Output.Origin{ .query = .callstack }) else false;
+ const location_rows = try restoreOutputLocationRows(p.gpa, content, saved.location_rows, is_callstack);
errdefer locations.freeRows(p.gpa, location_rows);
var mini: ?Mini.State = null;
@@ -1707,9 +1731,16 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool)
const row = if (context) @as(usize, @intCast(pane.wrap_line[i])) else body_line;
const at = if (context) 0 else body_at;
const text = if (row < total) sourceLine(pane, @intCast(row)) else "";
+ var guide_buffer: [1024]u8 = undefined;
+ const guide = if (at > 0 and width > 1 and f.output != null and
+ std.meta.eql(f.output.?.from, Output.Origin{ .query = .callstack }))
+ locations.treeContinuation(text, &guide_buffer, width - 1)
+ else
+ "";
+ const pad = displayWidth(guide);
// Headers use one screen row per source row, preserving signatures
// without allowing a long ancestor to consume the whole viewport.
- const end = if (width == 0 or context) text.len else fitEnd(text, at, width);
+ const end = if (width == 0 or context) text.len else fitEnd(text, at, width - pad);
const cut = if (pane.hscroll > 0 and width == 0)
modal.graphemeStart(text, @min(@as(usize, @intCast(pane.hscroll)), text.len))
else
@@ -1717,6 +1748,7 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool)
if ((width > 0 or pane.context_rows > 0) and record_wrap) {
pane.wrap_line[i] = @intCast(row);
pane.wrap_col[i] = @intCast(cut);
+ pane.wrap_pad[i] = @intCast(pad);
pane.wrap_n = @intCast(i + 1);
}
if (row < total) {
@@ -1735,6 +1767,8 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool)
}
if (dst) |out| @memcpy(out[written..][0..prefix.len], prefix);
written += prefix.len;
+ if (dst) |out| @memcpy(out[written..][0..guide.len], guide);
+ written += guide.len;
const shown = text[cut..end];
if (dst) |out| @memcpy(out[written..][0..shown.len], shown);
written += shown.len;
@@ -1935,7 +1969,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.
}
}.before);
var c: usize = 0;
- var screen_c: usize = 0;
+ const pad: usize = if (vr < pane.wrap_n) pane.wrap_pad[vr] else 0;
+ for (0..@min(pad, tw -| prefix_width)) |col| {
+ s.at(tx + @as(u16, @intCast(prefix_width + col)), body_y + vr).style.fg = .{ .rgb = p.bodyChrome().diagnostic_info };
+ }
+ var screen_c: usize = pad;
while (hs + c < limit and prefix_width + screen_c < tw) {
const grapheme_end = @min(limit, modal.nextGrapheme(line, hs + c));
const cells = graphemeDisplayWidth(line[hs + c .. grapheme_end]);
@@ -2218,8 +2256,8 @@ pub fn paintWordSelection(
if (next.line == row) hi = @min(hi, next.at);
const lo = @max(word_lo, here.at);
if (hi <= lo) continue;
- const c0 = @as(i32, prefix_width) + displayOffset(pane, row, here.at, lo);
- const c1 = @as(i32, prefix_width) + displayEndOffset(pane, row, here.at, hi - 1);
+ const c0 = @as(i32, prefix_width) + here.pad + displayOffset(pane, row, here.at, lo);
+ const c1 = @as(i32, prefix_width) + here.pad + displayEndOffset(pane, row, here.at, hi - 1);
var col = @max(@as(i32, prefix_width), c0);
while (col <= c1 and col < @as(i32, tw)) : (col += 1) {
const cell = s.at(tx + @as(u16, @intCast(col)), body_y + @as(u16, @intCast(vr)));