diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-25 10:27:05 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-25 11:58:11 -0300 |
| commit | bfdc8a9e61dd20c91b68f62187e724d1a98445a4 (patch) | |
| tree | a020fcbdc9ca8be68aa8983837accc2328f0e742 /src/Query.zig | |
| parent | 8bcaa657b39f24f0f2457f5c28e7095d5113ba73 (diff) | |
| download | pardes-bfdc8a9e61dd20c91b68f62187e724d1a98445a4.tar.gz pardes-bfdc8a9e61dd20c91b68f62187e724d1a98445a4.zip | |
query: a language server's list is answered, not typed: one place lands on it (Diagnostics too now), the place fed as the text's places so it is tinted and n/N have it, no query pane; several open the list with the keyboard on its current row in normal mode (showCurrent: the caret on the rows is the current row, n/N take it there), its target shown, Esc in it back to the text as it was; none is a message; line 1 keeps its word as text; Diagnostics keep the keyboard in the text for ]d; lsp-client and lsprelpath step with n, their goldens the caret on the row and no insert marker
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016u3hBPFfja5pK4EBRC1UVD
Diffstat (limited to 'src/Query.zig')
| -rw-r--r-- | src/Query.zig | 95 |
1 files changed, 91 insertions, 4 deletions
diff --git a/src/Query.zig b/src/Query.zig index 98419c7b..2ab687ee 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -1201,9 +1201,25 @@ pub fn fillList(p: *Pardes, owner_id: usize, source: Source, rows: []const u8) v const line = lineOne(rp.file.?.content); const a = parse(line) orelse return; makeListRows(p, qid, a.pat) catch |err| p.reportError(qid, "search", err); - // A list to pick from, typed into; diagnostics are a jump (]d): the - // keyboard stays on the place in the text. - if (source != .diagnostics) toLineOne(p, qid) else p.active = owner_id; + // Diagnostics are a jump (]d): the keyboard stays on the place in the + // text. The others are a list answered, not a query typed: the keyboard + // on the current row in normal mode (j, k, n, N step, Enter lands, Esc + // goes back), line 1 left as text for whoever wants to edit it. + if (source == .diagnostics) { + p.active = owner_id; + return; + } + tagline.exitHeader(p); + p.active = qid; + if (layout.findPane(p, qid)) |at| p.setActiveColumn(at.col); + rp.focus = .body; + const t = &rp.body; + if (t.mode == .insert) edit.exitInsert(p, t); + t.vsel.active = false; + t.nsel = 0; + t.cur_row = @intCast((q.current orelse 0) + 1); + showCurrent(rp); + showTarget(p, qid); } fn makeListRows(p: *Pardes, id: usize, pat: []const u8) !void { @@ -1334,12 +1350,25 @@ fn clearPlaces(p: *Pardes, q: *Query, serial: u32, owner_id: ?usize, asked: anyt /// is current. Scrolled into view, line 1 kept when it can be. fn showCurrent(rp: *Pane) void { const q = rp.query orelse return; - if (rp.body.cur_row != 0 and rp.focus == .body) return; + const on_rows = rp.body.cur_row != 0 and rp.focus == .body; + if (on_rows and rp.body.mode != .normal) return; const c = q.current orelse { rp.body.msel.active = false; return; }; const r: i32 = @intCast(c + 1); + if (on_rows) { + // The keyboard on the rows is the current row: n and N take it there. + rp.body.msel.active = false; + rp.body.cur_row = r; + rp.body.cur_col = 0; + rp.body.cur_pinned = true; + q.seen_row = r; + const off = rp.scroll(); + const shown = off + @as(i32, rp.rows) - 1; + if (r > shown) rp.scrollBy(r - shown) else if (r < off) rp.scrollBy(r - off); + return; + } rp.body.msel = .{ .active = true, .r0 = r, .r1 = r }; // Typed into, line 1 stays in view whatever the current row: what you // type is never scrolled away (the live rows start just before the @@ -1821,6 +1850,12 @@ pub fn key(p: *Pardes, id: usize, k: Key) bool { step(p, id, if (k.cp == 'n') 1 else -1); return true; } + // A language server's list, live: Esc is back to the text it was + // asked in, every view as it was. + if (hit(k, config.escape) and !q.frozen and q.lsp_rows.len > 0 and t.nsel == 0 and !t.vsel.active) { + cancel(p, id); + return true; + } if (hit(k, config.look_key) and t.cur_row > 0) { const i: usize = @intCast(t.cur_row - 1); if (i >= q.items.items.len or q.items.items[i].kind != .hit) return false; @@ -2341,3 +2376,55 @@ fn queryPane2(p: *Pardes, not: usize) ?usize { for (p.panes, 0..) |slot, i| if (slot) |pane| if (pane.query != null and i != not) return i; return null; } + +test "a language server's list: one answer lands with no pane, several open the list in normal mode on the current row, none is a message, Esc goes back" { + const lsp = pardes.lsp; + if (!lsp.supports.contains(.references) or !lsp.supports.contains(.diagnostics)) return; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha one\nbeta\nalpha two\ngamma\nalpha three\n"); + const npanes = struct { + fn of(pp: *Pardes) usize { + var n: usize = 0; + for (pp.panes) |slot| n += @intFromBool(slot != null); + return n; + } + }.of; + // One: the keyboard on it, no pane, the place tinted and n's. + p.lspRequest(0, .references, ""); + p.update(.{ .lsp_resp = .{ .id = p.lsp_wait.?.id, .rows = "/test.txt:3:1-5 alpha two\n" } }); + try std.testing.expectEqual(@as(usize, 1), npanes(p)); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); + try std.testing.expectEqual(@as(usize, 1), pane.places.hits.items.len); + try std.testing.expectEqual(Places.Hit{ .start = 15, .end = 20 }, pane.places.hits.items[0]); + // None: a message, no pane. + p.lspRequest(0, .diagnostics, ""); + p.update(.{ .lsp_resp = .{ .id = p.lsp_wait.?.id, .rows = "" } }); + try std.testing.expectEqual(@as(usize, 1), npanes(p)); + try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "none") != null); + // Several: the list open, the keyboard in it in normal mode on the + // current row, which the text shows; line 1 as text. + pane.body.cur_row = 0; + pane.body.cur_col = 0; + p.lspRequest(0, .references, ""); + p.update(.{ .lsp_resp = .{ .id = p.lsp_wait.?.id, .rows = "/test.txt:1:1-5 alpha one\n/test.txt:3:1-5 alpha two\n/test.txt:5:1-5 alpha three\n" } }); + const qid = queryPane(p).?; + const qp = p.panes[qid].?; + const q = qp.query.?; + try std.testing.expectEqual(qid, p.active); + try std.testing.expect(qp.body.mode == .normal); + try std.testing.expect(std.mem.startsWith(u8, qp.file.?.content, "Refs")); + try std.testing.expectEqual(@as(i32, @intCast(q.current.? + 1)), qp.body.cur_row); + try std.testing.expectEqual(@as(usize, 3), pane.places.hits.items.len); + const first = pane.places.current.?; + // n steps the rows, the caret with them, the text following. + typeKeys(p, "n"); + try std.testing.expectEqual(@as(i32, @intCast(q.current.? + 1)), qp.body.cur_row); + try std.testing.expectEqual(first + 1, pane.places.current.?); + // Esc: back to the text, as it was, the list gone. + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(p.panes[qid] == null); + try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); +} |
