summaryrefslogtreecommitdiff
path: root/core/body_layer.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/body_layer.zig')
-rw-r--r--core/body_layer.zig90
1 files changed, 90 insertions, 0 deletions
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 13fc7a85..13c24f97 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -472,6 +472,8 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
}
if (pane.file != null) paintTargets(p, s, arena, pane, r, tx, tw, body_y, body_h);
+ if (p.lsp_ask.hover != null) hoverGhosts(p, s, pane, tx, tw, body_y, body_h);
+ if (p.view().tag_state.kind == .rename) renameGhosts(p, s, pane, tx, tw, body_y, body_h);
// `gw`'s labels, two letters over the start of each word
if (pane.jump.items.len > 0) labels: {
@@ -632,6 +634,94 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
}
}
+/// A hover's answer as ghost lines under the line it was asked at (SPEC
+/// §3.5, R3): the rows below move down by its lines (those past the body's
+/// foot not shown meanwhile), the buffer untouched. Bounded by the rows
+/// shown and the hover's `Ask.hover_max` bytes.
+fn hoverGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void {
+ const h = &p.lsp_ask.hover.?;
+ if (h.serial != pane.serial) return;
+ const f = if (pane.file) |*file| file else return;
+ if (f.revision != h.revision) return;
+ const tab = p.settings.tab;
+ // The last row the line is shown on.
+ var under: ?u16 = null;
+ var row: u16 = pane.context_rows;
+ while (row < body_h) : (row += 1) {
+ if (pane.wrapAt(tab, row).line == h.row) under = row else if (under != null) break;
+ }
+ const at = under orelse return;
+ const text = std.mem.trimEnd(u8, h.text.slice(), "\n");
+ const k: u16 = @intCast(@min(std.mem.count(u8, text, "\n") + 1, body_h - at - 1));
+ if (k == 0) return;
+ var dst: u16 = body_h - 1;
+ while (dst >= at + 1 + k) : (dst -= 1) {
+ const to = @as(usize, body_y + dst) * s.cols + tx;
+ const from = @as(usize, body_y + dst - k) * s.cols + tx;
+ @memcpy(s.cells[to..][0..tw], s.cells[from..][0..tw]);
+ }
+ const th = p.theme();
+ const style: CellStyle = .{ .fg = .{ .rgb = th.tag_fg }, .bg = .{ .rgb = th.tag_bg } };
+ const gutter: u16 = File.gutterWidth(pane);
+ var lines = std.mem.splitScalar(u8, text, '\n');
+ for (0..k) |i| {
+ const y = body_y + at + 1 + @as(u16, @intCast(i));
+ s.fill(tx, y, tw, 1, .{ .bg = .{ .rgb = th.tag_bg } });
+ if (gutter + 2 < tw) _ = s.print(tx + gutter + 2, y, tw - gutter - 2, lines.next() orelse "", style);
+ }
+}
+
+/// A Rename typed in this body's tag, shown in its rows (SPEC §3.5, R3):
+/// each whole-word place of the name under the caret in the rows shown
+/// struck, the name typed after it, the rest of its row pushed right.
+/// Never written; bounded by the rows shown.
+fn renameGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y: u16, body_h: u16) void {
+ const host = TagState.hostOf(p) orelse return;
+ if (p.panes[host] != pane or pane.file == null) return;
+ const old = @import("lsp/Ask.zig").renamedWord(pane) orelse return;
+ const new = p.view().tag_state.field.text();
+ const tab = p.settings.tab;
+ const chrome = p.chromeTheme();
+ const th = p.theme();
+ const added: CellStyle = .{ .fg = .{ .rgb = chrome.diagnostic_hint }, .bg = if (th.bg) |c| .{ .rgb = c } else .default, .bold = true };
+ const wide: u16 = @intCast(@min(File.displayWidth(tab, new), tw));
+ const gutter: i32 = File.gutterWidth(pane);
+ var row: u16 = pane.context_rows;
+ while (row < body_h) : (row += 1) {
+ const w = pane.wrapAt(tab, row);
+ if (w.line < 0) continue;
+ const line = File.sourceLine(pane, w.line);
+ const from: usize = @min(line.len, @as(usize, @intCast(@max(0, w.at))));
+ const next = pane.wrapAt(tab, row + 1);
+ const to: usize = if (next.line == w.line) @min(line.len, @as(usize, @intCast(@max(0, next.at)))) else line.len;
+ // Right to left, so a push leaves the places before it where they are.
+ var end = to;
+ while (std.mem.lastIndexOf(u8, line[from..end], old)) |k| {
+ const at = from + k;
+ end = at;
+ const before = at > 0 and (std.ascii.isAlphanumeric(line[at - 1]) or line[at - 1] == '_');
+ const after = at + old.len < line.len and (std.ascii.isAlphanumeric(line[at + old.len]) or line[at + old.len] == '_');
+ if (before or after) continue;
+ const c0 = gutter + w.pad + File.displayOffset(tab, pane, w.line, w.at, @intCast(at));
+ const c1 = gutter + w.pad + File.displayOffset(tab, pane, w.line, w.at, @intCast(at + old.len));
+ if (c0 < gutter or c1 > tw) continue;
+ const y = body_y + row;
+ var c: u16 = @intCast(c0);
+ while (c < c1) : (c += 1) {
+ const cell = s.at(tx + c, y);
+ cell.style.strikethrough = true;
+ cell.style.fg = .{ .rgb = chrome.diagnostic_error };
+ }
+ const x: u16 = @intCast(c1);
+ if (x + wide < tw) {
+ const cells = s.cells[@as(usize, y) * s.cols + tx ..][0..tw];
+ std.mem.copyBackwards(Cell, cells[x + wide ..], cells[x .. tw - wide]);
+ }
+ _ = s.print(tx + x, y, tw - x, new, added);
+ }
+ }
+}
+
/// The line a motion role would go to from the caret of `pane`, looked for
/// in lines `lo` to `hi` (the rows shown) alone; null for none there, or a
/// role that is no line's.