summaryrefslogtreecommitdiff
path: root/core/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/look.zig')
-rw-r--r--core/look.zig50
1 files changed, 25 insertions, 25 deletions
diff --git a/core/look.zig b/core/look.zig
index e075bbae..b2a7b945 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -311,7 +311,7 @@ pub fn submitSearch(p: *Pardes, id: usize) void {
if (normal.selRegexArmed(pane)) |a| {
// helix keeps the pattern in `/`
if (a.pat.len > 0) {
- p.registers.put(p.gpa, '/', a.pat, 0, 1, true) catch |err| return p.reportError(id, "search", err);
+ p.registers.put(p.gpa, '/', a.pat, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err);
p.registers.last_search = '/';
}
return if (panes.promptTarget(p, pane)) |t| normal.applySelRegex(p, pane, t, a.pat, a.mode);
@@ -321,10 +321,10 @@ pub fn submitSearch(p: *Pardes, id: usize) void {
if (std.mem.startsWith(u8, armed, config.rename_marker)) return p.lspRequest(id, .rename, armed[slash + 1 ..]);
if (std.mem.startsWith(u8, armed, config.symbol_marker)) return p.lspRequest(id, .workspace_symbols, armed[slash + 1 ..]);
// A PDF's `/` and a terminal's: a text's is its query pane (Query.zig).
- _ = runSearch(p, id, armed[slash + 1 ..], .top, true) catch |err| return p.reportError(id, "search", err);
+ _ = runSearch(p, id, armed[slash + 1 ..], .top, true) catch |err| return p.reportError(.at(id), "search", err);
var pattern: std.ArrayList(u8) = .empty;
- normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch |err| return p.reportError(id, "search", err);
- p.registers.put(p.gpa, '/', pattern.items, 0, 1, true) catch |err| return p.reportError(id, "search", err);
+ normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch |err| return p.reportError(.at(id), "search", err);
+ p.registers.put(p.gpa, '/', pattern.items, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err);
p.registers.last_search = '/';
lookFirstHit(p, id);
}
@@ -756,7 +756,7 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, ke
}
fn selectSpan(p: *Pardes, pane: *Pane, at: Spot) void {
- const text = edit.flatSurface(p.editor(), &pane.body) catch |err| return p.reportError(p.view().active, "look", err);
+ const text = edit.flatSurface(p.editor(), &pane.body) catch |err| return p.reportError(.at(p.view().active), "look", err);
// saturating, not `- 1`: `f.zig:0-5` is a legal thing to type and a
// 1-based zero is the same nothing an absent number is
const acol: i32 = @intCast(at.col -| 1);
@@ -952,7 +952,7 @@ fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void {
var msg: Kind.Buf(miss_path_cap + 72) = .{};
// Shown on the pane; logged once, as the err below, not a msg too.
p.fs.unlogged = true;
- p.setMessage(id, msg.print("Look: {s}", .{why}));
+ p.setMessage(.at(id), msg.print("Look: {s}", .{why}));
p.fs.unlogged = false;
const serial = if (p.panes[id]) |pane| pane.serial else 0;
var rec: Kind.Buf(miss_path_cap + 96) = .{};
@@ -1047,7 +1047,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text:
p.word_look = true;
defer p.word_look = false;
const rows = runSearch(p, id, text, .cursor, false) catch |err| {
- p.reportError(id, "search", err);
+ p.reportError(.at(id), "search", err);
return;
};
if (rows == 0) {
@@ -1123,7 +1123,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void {
var placed: Kind.Buf(miss_path_cap + "…".len + 24) = .{};
const place = placed.print("{s}:{d}", .{ name, line });
if (!opened_here) return missedLine(p, target, place, line);
- p.removePane(target, null) catch |err| p.reportError(id, "look", err);
+ p.removePane(target, null) catch |err| p.reportError(.at(id), "look", err);
if (p.panes[id] != null) v.active = id;
return missedLine(p, id, place, line);
} else |_| {}
@@ -1163,7 +1163,7 @@ fn lookKind(p: *Pardes, id: usize, target: usize, expr_raw: []const u8, opened:
if (opened) {
var kept: [miss_path_cap + "…".len]u8 = undefined;
@memcpy(kept[0..name.len], name);
- p.removePane(target, null) catch |err| p.reportError(id, "look", err);
+ p.removePane(target, null) catch |err| p.reportError(.at(id), "look", err);
if (p.panes[id] != null) p.view().active = id;
return missed(p, id, "{s} {s}", .{ kept[0..name.len], if (said.len > 0) said.slice() else "is no text to address" });
}
@@ -1179,7 +1179,7 @@ fn spotText(at: Spot, buf: *[41]u8) []const u8 {
fn closeAndMiss(p: *Pardes, id: usize, opened: usize, name: []const u8, why: []const u8) void {
var kept: [miss_path_cap + "…".len]u8 = undefined;
@memcpy(kept[0..name.len], name);
- p.removePane(opened, null) catch |err| p.reportError(id, "look", err);
+ p.removePane(opened, null) catch |err| p.reportError(.at(id), "look", err);
if (p.panes[id] != null) p.view().active = id;
missed(p, id, "{s}: {s}", .{ kept[0..name.len], why });
}
@@ -1197,8 +1197,8 @@ fn lookTerminalAddress(p: *Pardes, id: usize, target: usize, expr: []const u8) v
var dot: u32 = 0;
for (lines, 0..) |ln, i| {
if (i == row) dot = @intCast(text.items.len + @min(ln.len, @as(usize, @intCast(@max(0, pane.body.cur_col)))));
- text.appendSlice(arena, ln) catch |err| return p.reportError(id, "look", err);
- text.append(arena, '\n') catch |err| return p.reportError(id, "look", err);
+ text.appendSlice(arena, ln) catch |err| return p.reportError(.at(id), "look", err);
+ text.append(arena, '\n') catch |err| return p.reportError(.at(id), "look", err);
}
var a: Addr = .{ .text = text.items, .lim = null, .expr = expr };
const r = a.address(.{ .q0 = dot, .q1 = dot }) orelse return missed(p, id, "{s}", .{a.err});
@@ -1266,7 +1266,7 @@ pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void {
if (at.line > n or at.end_line > n) {
var said: Kind.Buf(miss_path_cap + 64) = .{};
var cut: [miss_path_cap + "…".len]u8 = undefined;
- p.setMessage(id, said.print("{s} has {d} lines now: at its last", .{ missText(path, &cut), n }));
+ p.setMessage(.at(id), said.print("{s} has {d} lines now: at its last", .{ missText(path, &cut), n }));
}
}
@@ -1393,7 +1393,7 @@ fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize,
const shown = p.panes[p.view().active] orelse return;
const f = if (shown.file) |*file| file else return;
if (at.line > panes.File.nlines(p.gpa, f)) {
- if (opened) |free| p.removePane(free, null) catch |err| p.reportError(id, "look", err);
+ if (opened) |free| p.removePane(free, null) catch |err| p.reportError(.at(id), "look", err);
if (p.panes[before] != null) p.view().active = before;
return missedLine(p, id, path, at.line);
}
@@ -1415,7 +1415,7 @@ fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool {
/// A file that is there but would not open: said with its path, `look:
/// <path>: permission denied`, the path cut in its middle when long.
fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
- if (@import("Messages.zig").dialReason(err) != null) return p.reportError(id, path, err);
+ if (@import("Messages.zig").dialReason(err) != null) return p.reportError(.at(id), path, err);
var cut: [miss_path_cap + "…".len]u8 = undefined;
// Not there, on a peer's mount as on this host: a miss, the write
// answered, as any path to no file is.
@@ -1423,7 +1423,7 @@ fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
if (err == error.FileNotFound or err == error.NotFound or remote_missing)
return missed(p, id, "{s}: no such file", .{missText(path, &cut)});
var said: Kind.Buf(miss_path_cap + 16) = .{};
- p.reportError(id, said.print("look: {s}", .{missText(path, &cut)}), err);
+ p.reportError(.at(id), said.print("look: {s}", .{missText(path, &cut)}), err);
}
pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
@@ -1468,7 +1468,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
break :looked operand;
};
// The operand may borrow selected terminal/PDF text released below.
- const txt = p.scratch.allocator().dupe(u8, looked) catch |err| return p.reportError(id, "look", err);
+ const txt = p.scratch.allocator().dupe(u8, looked) catch |err| return p.reportError(.at(id), "look", err);
// A trailing `:` (`a.txt:2:3:`, as a compiler's message ends) is no
// part of the place, as a click's expansion leaves it off.
const bare = std.mem.trimEnd(u8, std.mem.trim(u8, txt, " \t\r\n"), ":");
@@ -1586,7 +1586,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
const before = v.active;
var opened: ?usize = null;
if (!focusPaneByPath(p, target.path, target.at)) {
- const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots);
+ const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots);
const nt = panes.File.open(p, free, target.path, target.at.line) catch |err|
return lookOpenFailed(p, id, target.path, err);
if (target.at.col > 0) nt.body.cur_col = @intCast(target.at.col - 1);
@@ -1624,7 +1624,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
if (target.at.line > 0) lookKind(p, id, v.active, spotText(target.at, &place), false);
return;
}
- const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots);
+ const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots);
const made = Kind.openFile(p, free, target.kind, target.path) catch |err|
return lookOpenFailed(p, id, target.path, err);
// One its kind refuses (an image corrupt, truncated, not what
@@ -1975,19 +1975,19 @@ test "cwd changes cancel only the affected pane's Look hover" {
const first = p.panes[0] orelse return error.MissingFirstPane;
const other = p.panes[1] orelse return error.MissingOtherPane;
- p.setCwd(0, "/work/first");
- p.setCwd(1, "/work/other");
+ p.setCwd(.at(0), "/work/first");
+ p.setCwd(.at(1), "/work/other");
p.look_hover_wait = .{ .col = 1, .row = 1, .pane = 0, .serial = first.serial };
// Hosts poll cwd every frame. An unchanged answer is observational and a
// change reported for another pane cannot invalidate this pane's operand.
- p.setCwd(0, "/work/first");
+ p.setCwd(.at(0), "/work/first");
try std.testing.expect(p.look_hover_wait != null);
- p.setCwd(1, "/work/elsewhere");
+ p.setCwd(.at(1), "/work/elsewhere");
try std.testing.expect(p.look_hover_wait != null);
try std.testing.expectEqual(other.serial, p.panes[1].?.serial);
- p.setCwd(0, "/work/changed");
+ p.setCwd(.at(0), "/work/changed");
try std.testing.expect(p.look_hover_wait == null);
try std.testing.expect(p.look_hover_preview == null);
}
@@ -2671,7 +2671,7 @@ test "Plumb: a look sends what it looks at, the rules written first: a rule's wo
const opened = p.view().active;
try std.testing.expect(opened != 0);
p.view().active = 0;
- p.setMessage(0, "before");
+ p.setMessage(.at(0), "before");
lookAt(p, 0, pic);
try std.testing.expectEqual(opened, p.view().active);
try std.testing.expectEqualStrings("before", pane.msg[0..pane.msg_len]);