summaryrefslogtreecommitdiff
path: root/src/lsp/Ask.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/lsp/Ask.zig')
-rw-r--r--src/lsp/Ask.zig61
1 files changed, 40 insertions, 21 deletions
diff --git a/src/lsp/Ask.zig b/src/lsp/Ask.zig
index c658593d..f071cf7b 100644
--- a/src/lsp/Ask.zig
+++ b/src/lsp/Ask.zig
@@ -17,6 +17,25 @@ const config = @import("../config.zig");
const memory = @import("../memory.zig");
const Pardes = pardes.Pardes;
const Pane = panes.Pane;
+const Effect = pardes.Effect;
+
+const Ask = @This();
+
+seq: u32 = 0,
+/// The last query asked (Lspwhy explains it): its kind, argument, and the
+/// pane and place it was asked at.
+last: ?struct { kind: lsp.Kind, arg: Effect.Buf(128), serial: u32, offset: u32 } = null,
+/// The query whose answer is awaited.
+wait: ?struct {
+ id: u32,
+ kind: lsp.Kind,
+ pane: usize,
+ serial: u32,
+ revision: u32,
+ arg: Effect.Buf(128),
+ row: i32 = 0,
+ col: i32 = 0,
+} = null,
const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET;
pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) void {
@@ -24,7 +43,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
if (!normal.multiOnce(p)) return; // one question per keystroke, from the primary
// Lspwhy narrates the last query where it was asked -- that pane's
// file, place and argument -- from wherever it is run.
- const last_pane: ?usize = if (kind == .explain) (if (p.lsp_last) |last| p.paneBySerial(last.serial) else null) else null;
+ const last_pane: ?usize = if (kind == .explain) (if (p.lsp_ask.last) |last| p.paneBySerial(last.serial) else null) else null;
const id = last_pane orelse asked;
var said: [128]u8 = undefined;
if (!lsp.supports.contains(kind))
@@ -73,16 +92,16 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
var sent = arg;
var at = off;
if (kind == .explain) {
- if (p.lsp_last) |last| {
+ if (p.lsp_ask.last) |last| {
sent = std.fmt.bufPrint(&explained, "{s} {s}", .{ @tagName(last.kind), last.arg.slice() }) catch "";
if (last_pane != null) at = last.offset;
}
- } else if (kind != .status) p.lsp_last = .{ .kind = kind, .arg = .from(arg), .serial = pane.serial, .offset = @intCast(off) };
- p.lsp_seq +%= 1;
+ } else if (kind != .status) p.lsp_ask.last = .{ .kind = kind, .arg = .from(arg), .serial = pane.serial, .offset = @intCast(off) };
+ p.lsp_ask.seq +%= 1;
// A 9P write that asked it is answered once the answer is in.
if (p.fs.serving) p.fs.lsp_answer_at = pardes.turn.lsp_answers;
- p.lsp_wait = .{
- .id = p.lsp_seq,
+ p.lsp_ask.wait = .{
+ .id = p.lsp_ask.seq,
.kind = kind,
.pane = id,
.serial = pane.serial,
@@ -92,7 +111,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
.col = pane.body.cur_col,
};
p.emit(.{ .lsp = .{
- .id = p.lsp_seq,
+ .id = p.lsp_ask.seq,
.kind = kind,
.pane = @intCast(id),
.offset = @intCast(at),
@@ -246,9 +265,9 @@ fn lspWord(kind: lsp.Kind) []const u8 {
pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
defer pardes.turn.bump(&pardes.turn.lsp_answers);
- const w = p.lsp_wait orelse return;
+ const w = p.lsp_ask.wait orelse return;
if (w.id != id) return; // superseded by a newer press, or the pane died
- p.lsp_wait = null;
+ p.lsp_ask.wait = null;
const pane = p.panes[w.pane] orelse return;
if (pane.serial != w.serial) return;
// Whatever fails from here -- no answer, nothing found, no room for
@@ -414,7 +433,7 @@ test "Lspwhy after a Hover asks to explain that hover, in its file at its place,
};
pane.body.cur_row = 0;
pane.body.cur_col = 0;
- p.lsp_wait = null;
+ p.lsp_ask.wait = null;
// Run from another file's pane: still the hover's file and place.
const other = p.freeSlot().?;
_ = try panes.openTutorView(p, other);
@@ -452,7 +471,7 @@ test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all r
try std.testing.expect(at == null);
at = e.lsp.offset;
};
- q.lsp_wait = null;
+ q.lsp_ask.wait = null;
return at orelse error.NothingAsked;
}
};
@@ -509,7 +528,7 @@ test "Callstack always opens and focuses its own pane, reusing it for another sy
_ = try p.setTestFile("fn work() {}\n");
const source = p.panes[0].?;
p.lspRequest(0, .callstack, "");
- const first = p.lsp_wait orelse return error.NoRequest;
+ const first = p.lsp_ask.wait orelse return error.NoRequest;
lspResponse(p, first.id, "╰──┬ /test.txt:1:4-7 work\n@callstack-match ╰─ /test.txt:1:4-7 fn work() {}\n");
const report = p.panes[p.active].?;
try std.testing.expect(report != source);
@@ -534,7 +553,7 @@ test "Callstack always opens and focuses its own pane, reusing it for another sy
try std.testing.expectEqual(@as(usize, 0), report.body.nsel);
const serial = report.serial;
p.lspRequest(0, .callstack, "");
- const second = p.lsp_wait orelse return error.NoRequest;
+ const second = p.lsp_ask.wait orelse return error.NoRequest;
lspResponse(p, second.id, "No callers reported\n");
try std.testing.expectEqual(serial, p.panes[p.active].?.serial);
try std.testing.expectEqualStrings("No callers reported\n", p.panes[p.active].?.file.?.content);
@@ -546,7 +565,7 @@ test "Callers with one answer jumps to it and says where, in a msg" {
defer p.deinit();
const pane = try p.setTestFile("fn a() {}\nfn b() { a(); }\n");
p.lspRequest(p.active, .incoming_calls, "");
- const wait = p.lsp_wait.?;
+ const wait = p.lsp_ask.wait.?;
p.update(.{ .lsp_resp = .{ .id = wait.id, .rows = "/test.txt:2:10 b\n" } });
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
try std.testing.expectEqualStrings("Callers: the one, /test.txt:2:10", pane.msg[0..pane.msg_len]);
@@ -558,7 +577,7 @@ test "a Rename the language server finds nothing for says so, and changes nothin
defer p.deinit();
const pane = try p.setTestFile("const value=1;\n");
p.lspRequest(p.active, .rename, "renamed");
- const wait = p.lsp_wait.?;
+ const wait = p.lsp_ask.wait.?;
p.update(.{ .lsp_resp = .{ .id = wait.id, .rows = "" } });
try std.testing.expectEqualStrings("Rename: nothing here to rename", pane.msg[0..pane.msg_len]);
try std.testing.expectEqualStrings("const value=1;\n", pane.file.?.content);
@@ -573,19 +592,19 @@ test "LSP failure clears only its matching wait without completion indentation"
pane.body.cur_col = 1;
p.lspRequest(p.active, .completion, "");
- const old_id = p.lsp_wait.?.id;
+ const old_id = p.lsp_ask.wait.?.id;
p.lspRequest(p.active, .completion, "");
- const current_id = p.lsp_wait.?.id;
+ const current_id = p.lsp_ask.wait.?.id;
p.update(.{ .lsp_resp = .{ .id = old_id, .rows = null } });
- try std.testing.expectEqual(current_id, p.lsp_wait.?.id);
+ try std.testing.expectEqual(current_id, p.lsp_ask.wait.?.id);
p.update(.{ .lsp_resp = .{ .id = current_id, .rows = null } });
- try std.testing.expect(p.lsp_wait == null);
+ try std.testing.expect(p.lsp_ask.wait == null);
try std.testing.expectEqualStrings("x", pane.file.?.content);
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
p.lspRequest(p.active, .completion, "");
- p.update(.{ .lsp_resp = .{ .id = p.lsp_wait.?.id, .rows = "" } });
- try std.testing.expect(p.lsp_wait == null);
+ p.update(.{ .lsp_resp = .{ .id = p.lsp_ask.wait.?.id, .rows = "" } });
+ try std.testing.expect(p.lsp_ask.wait == null);
try std.testing.expectEqualStrings("x ", pane.file.?.content);
try std.testing.expectEqual(@as(i32, 4), pane.body.cur_col);
}