diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 22:51:55 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 22:51:55 -0300 |
| commit | 5d091b37b4641c274900d4d02b7f1d61b5a9301f (patch) | |
| tree | 0820b7b6c0ebd3a614658437b862f0f200d47964 /core/body_layer.zig | |
| parent | 806dc79a694c9df50cf3e13e9091986ebc74cb96 (diff) | |
| download | pardes-5d091b37b4641c274900d4d02b7f1d61b5a9301f.tar.gz pardes-5d091b37b4641c274900d4d02b7f1d61b5a9301f.zip | |
lsp: a hover (SPC l k) and a rename (SPC l r) asked from the keyboard show in the edited pane's own body: the hover as ghost lines under the line it was asked at, no +Hover pane, Esc taking them away; Rename typed in that pane's tag (` Rename best → bester▌`, the old name struck), each whole-word place of the old name in the rows shown drawn struck with the new name after it as it is typed, Enter asking the server for it (its edits applied as before), Esc asking nothing (pick-ui SPEC §3.5, §14.1, R3, walk UI line F item 3, its hover and rename; code actions NOT done: the protocol client sends an action's title alone, no edit to preview or apply): Ask.hover (its pane, line, revision and first 1,024 bytes, in the dump; an edit of the text stops it showing), body_layer.hoverGhosts and renameGhosts (drawn after the rows as the message ghosts are, the rows below pushed down or a row's cells pushed right, never written, the rows shown alone), TagState.Kind.rename (its head; no band), Ask.openRename and renameKey, the name under the caret Ask.renamedWord (the preview is pardes's own whole-word match in view, the edit the server's on Enter); under `Jumps new-pane` or from a 9P script, +Hover and the rename prompt as before; TESTS: Ask.zig "a hover asked from the keyboard is ghost lines ..." and "SPC l r types the new name in the pane's own tag ..."; core-test 1029/1196 (167 skipped), 0 failed, load 8
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/body_layer.zig')
| -rw-r--r-- | core/body_layer.zig | 90 |
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. |
