summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/search-proto-converge.md12
-rw-r--r--docs/typ/guide.typ2
-rw-r--r--src/Query.zig95
-rw-r--r--src/pardes.zig13
-rw-r--r--test/output.zig6
-rw-r--r--test/snapshots/lsp-client.golden4
-rw-r--r--test/snapshots/lsp-client.snap10
-rw-r--r--test/snapshots/lsprelpath.golden8
-rw-r--r--test/snapshots/lsprelpath.snap7
9 files changed, 136 insertions, 21 deletions
diff --git a/docs/search-proto-converge.md b/docs/search-proto-converge.md
index 4c7b7006..af9068a0 100644
--- a/docs/search-proto-converge.md
+++ b/docs/search-proto-converge.md
@@ -56,6 +56,18 @@ end without a word; with no places (or after an `s` changed the register)
they are helix's register search as before. `]d` / `[d` step the
diagnostics' places once a Diagnostics query fed them.
+**A language server's list is answered, not typed.** `gd`, `gr`, `gi`
+and `SPC l d` ask; the answer decides: one place is a jump (the keyboard
+on it, the place that text's places, so it is tinted and n/N have it; no
+query pane); several open the query pane with its rows there and the
+keyboard in its normal mode on the current row (the first after where it
+was asked), its target shown, so j/k/n/N step, Enter lands and Esc goes
+back to the text as it was; none is a message. Line 1 reads `Refs` as text
+(B2 asks again; editing it to `/x` works), but no language key puts the
+keyboard there in insert mode. Diagnostics keep the keyboard in the text
+so `]d`/`[d` step their places. `Symbols` (`SPC s s`) is fuzzy, typed
+into: a query.
+
**The current row shows its target**, the keyboard staying on line 1: a
place in an open pane's text is selected there and scrolled into view
(remembered for Esc); a file an open pane shows, its line there; any other
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index d479a884..4b783c64 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -193,7 +193,7 @@ Line 1's first word names what it searches, and editing the word changes it:
[`Panes name`], [the open panes, then the ones closed this session, `(closed)` and dimmer: #key("Enter") (or a #word("Look") at its `@pN`) brings one back where it was, its text with it (#key("SPC b b"), #word("Panes"))],
[`Symbols name`], [the text's declarations (#key("SPC s s"))],
[`All pat`], [every open pane's text, its rows under each pane (#key("SPC /"))],
- [`Refs`, `Def`, `Impl`, `Diagnostics`], [the language server's lists; their places in the text tinted as a `/`'s are, `]d` stepping the diagnostics],
+ [`Refs`, `Def`, `Impl`, `Diagnostics`], [the language server's lists (#key("gr"), #key("gd"), #key("gi"), #key("SPC l d")): one answer is a jump, none a message; several open the list with the keyboard on its current row in normal mode (#keys("j", "k", "n", "N") step it, #key("Enter") lands, #key("Esc") goes back), the diagnostics' keeping it in the text for `]d`; their places in the text tinted as a `/`'s are],
)
A row in a file no pane shows is shown in a `+Preview` under the query
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);
+}
diff --git a/src/pardes.zig b/src/pardes.zig
index a23039ef..a35d1604 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -7093,11 +7093,22 @@ pub const Pardes = struct {
const from: panes.Output.Origin = .{ .query = w.kind };
const nrows = std.mem.count(u8, rows, "\n");
- if (panes.Output.traits(from).jumps and nrows == 1) {
+ if ((panes.Output.traits(from).jumps or w.kind == .diagnostics) and nrows == 1) {
const ln = std.mem.trimEnd(u8, rows, "\n");
const place = ln[0..panes.Output.location(ln).end];
p.look_missed = false;
look.lookAt(p, w.pane, place);
+ // The one place is the text's places, as a list's would be: tinted,
+ // and n and N step it.
+ const spot = look.parsePathLine(place);
+ if (!p.look_missed and spot.at.line > 0) if (p.panes[p.active]) |there| if (there.file) |*tf| if (spot.at.line <= panes.File.nlines(p.gpa, tf)) {
+ const ls = panes.File.lineStart(p.gpa, tf, spot.at.line - 1);
+ const line = tf.content[ls .. std.mem.indexOfScalarPos(u8, tf.content, ls, '\n') orelse tf.content.len];
+ const col = @min(spot.at.col -| 1, line.len);
+ // To its end when the server said it, else the word there.
+ const end = if (spot.at.end_line == spot.at.line and spot.at.end_col > col) @min(spot.at.end_col, line.len) else if (look.expandedWord(line, col)) |word| word.hi else col + 1;
+ if (ls + end <= tf.content.len) there.places.feed(p, there, 0, &.{.{ .start = ls + col, .end = ls + end }}, ls + col);
+ };
// A word that asks for a list (Callers, Refs) with one answer
// jumps to it with no list: where it went is said, as the list
// would have shown it. A definition's jump is the answer itself.
diff --git a/test/output.zig b/test/output.zig
index 8eb389c8..530db77c 100644
--- a/test/output.zig
+++ b/test/output.zig
@@ -219,9 +219,11 @@ test "references fill the asking text's query pane: sorted under their files, th
try std.testing.expectEqual(@as(?usize, 2), source.places.current);
try std.testing.expectEqual(@as(i32, 3), source.body.cur_row);
try std.testing.expectEqual(@as(usize, 6), results.query.?.total);
- // Ctrl-n on line 1, Enter: the keyboard on that ref in the text
+ // A list answered, not a query typed: the keyboard on its current row in
+ // normal mode; n, Enter: the keyboard on that ref in the text
try std.testing.expectEqual(qid, p.active);
- p.update(.{ .key = .{ .cp = 'n', .ctrl = true } });
+ try std.testing.expect(results.body.mode == .normal and results.body.cur_row > 0);
+ p.update(.{ .key = .{ .cp = 'n' } });
try std.testing.expectEqual(@as(?usize, 3), source.places.current);
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(@as(usize, 0), p.active);
diff --git a/test/snapshots/lsp-client.golden b/test/snapshots/lsp-client.golden
index 18ccd775..f3d7006e 100644
--- a/test/snapshots/lsp-client.golden
+++ b/test/snapshots/lsp-client.golden
@@ -15,9 +15,9 @@
| 3 a + b
| 4 }
| 5
-== snap gr-list grid=100x25 cursor=7,14
+== snap gr-list grid=100x25 cursor=2,16
|3: 1 mod lib;
-|13: ^ +Search 1/3 Del
+|13: +Search 1/3 Del
|14: Refs
|15: lib.rs
|16: 2 pub fn add(a: i32, b: i32) -> i32 {
diff --git a/test/snapshots/lsp-client.snap b/test/snapshots/lsp-client.snap
index d9827a2a..159bf80e 100644
--- a/test/snapshots/lsp-client.snap
+++ b/test/snapshots/lsp-client.snap
@@ -7,7 +7,8 @@
# and the message row still carries the server's settled state
# ("lsp lspmock: ready") because nothing has cleared it yet.
# gr -> the text's query pane, line 1 `Refs`, rows under their files,
-# the next occurrence current; n/N step the places in the text.
+# the next occurrence current, the keyboard on it in normal mode
+# (a list answered, not a query typed); n/N step the places.
file main.rs mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n
file lib.rs // mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n
start 25 100 main.rs
@@ -27,9 +28,10 @@ key r
wait 10000 add(3, 4)
stable 700 15000
snap gr-list
-# Ctrl-n on line 1 steps to the next hit, Enter lands there; N in the text
-# goes back to the one before, round the places in main.rs
-key c-n
+# the list opens in normal mode, the caret on the current row: n steps to
+# the next hit, Enter lands there; N in the text goes back to the one
+# before, round the places in main.rs
+key n
key enter
stable 700 15000
snap gr-opened
diff --git a/test/snapshots/lsprelpath.golden b/test/snapshots/lsprelpath.golden
index 59a3c5d0..6351de03 100644
--- a/test/snapshots/lsprelpath.golden
+++ b/test/snapshots/lsprelpath.golden
@@ -1,4 +1,4 @@
-== snap absrow grid=100x35 cursor=7,17
+== snap absrow grid=100x35 cursor=2,21
| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit
| New Tty Find Grep Joincol Delcol
| /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse TreeContext Def Refs Del
@@ -15,7 +15,7 @@
|
|
|
-|^ +Search 2/2 Del
+| +Search 2/2 Del
| Refs
| /tmp/pardes-snap/lsprelpath/cwd/shade.zig
| 1 pub const Shade = enum {
@@ -72,7 +72,7 @@
|32: 0-0 d,#608269, 1-99 d,#0d1410,
|33: 0-0 d,#608269, 1-99 d,#0d1410,
|34: 0-0 d,#608269, 1-99 d,#0d1410,
-== snap subrow grid=100x35 cursor=7,17
+== snap subrow grid=100x35 cursor=2,21
| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit
| New Tty Find Grep Joincol Delcol
| /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse TreeContext Def Refs Del
@@ -89,7 +89,7 @@
|
|
|
-|^ +Search 2/2 Del
+| +Search 2/2 Del
| Refs
| inner/tint.zig
| 1 pub const Tint = enum {
diff --git a/test/snapshots/lsprelpath.snap b/test/snapshots/lsprelpath.snap
index 8420e134..70ca3fdc 100644
--- a/test/snapshots/lsprelpath.snap
+++ b/test/snapshots/lsprelpath.snap
@@ -44,8 +44,9 @@ wait 15000 cwd/shade.zig
stable 700 15000
snap absrow
# the current row is parent.zig's own; the one before it is shade.zig's,
-# shown in the +Preview, which Enter makes shade.zig's pane
-key c-p
+# shown in the +Preview (N, the list in normal mode), which Enter makes
+# shade.zig's pane
+key N
wait 10000 verdigris
stable 700 15000
key enter
@@ -63,7 +64,7 @@ key r
wait 15000 inner/tint.zig
stable 700 15000
snap subrow
-key c-p
+key N
wait 10000 ochre
stable 700 15000
key enter