summaryrefslogtreecommitdiff
path: root/src/lsp/Ask.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 13:16:39 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit961bea06443e25a92e02be58136065c2a1ea84c1 (patch)
tree983433b6ec9b5855530e187ccc2e8a783b8fd42e /src/lsp/Ask.zig
parent80f4398f1fed8d46d73cab8045005c02189b34fc (diff)
downloadpardes-961bea06443e25a92e02be58136065c2a1ea84c1.tar.gz
pardes-961bea06443e25a92e02be58136065c2a1ea84c1.zip
idioms #15, the catch unreachable sites slice b added, re-classified: 29 that a word, a path, an id or a function's text could reach go back to a cut through Kind.Buf (or, at echoCommand's and Repl's writers, a failure handled once at the writer), 95 stay because every argument is an integer, a literal, a comptime word or a cut in the same statement (one added to Ask's arg, ctl's why, choices, word and the ids and fields paneText writes, events' records and Edit's names), each with its reason on its line
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/lsp/Ask.zig')
-rw-r--r--src/lsp/Ask.zig18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/lsp/Ask.zig b/src/lsp/Ask.zig
index 76c32f2d..6b5dd8c8 100644
--- a/src/lsp/Ask.zig
+++ b/src/lsp/Ask.zig
@@ -60,7 +60,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
const zig_buf = if (pane.file) |f| std.mem.endsWith(u8, f.path, ".zig") else true;
if ((zig_buf and (!std.zig.isValidId(arg) or std.zig.isUnderscore(arg))) or
(!zig_buf and std.mem.indexOfAny(u8, arg, " \t\r\n\"\\") != null))
- return p.reportFailure(id, std.fmt.bufPrint(&said, "Rename: {s} is no name", .{arg}) catch unreachable); // arg is 128 at most
+ return p.reportFailure(id, std.fmt.bufPrint(&said, "Rename: {s} is no name", .{arg[0..@min(arg.len, 128)]}) catch unreachable); // 128 and 19 fit 160
}
var off = if (pane.file) |f| modal.offsetAt(f.content, .{
.row = @intCast(@max(0, pane.body.cur_row)),
@@ -83,7 +83,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
}
}
off = nearest orelse
- return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: no {s} in this file", .{ lspWord(kind), arg }) catch unreachable); // a word, 128 and 18 fit 160
+ return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: no {s} in this file", .{ lspWord(kind), arg[0..@min(arg.len, 128)] }) catch unreachable); // a literal word, 128 and 18 fit 160
arg = "";
}
// Lspwhy asks the last query again, narrated: its kind and argument,
@@ -93,7 +93,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
var at = off;
if (kind == .explain) {
if (p.lsp_ask.last) |last| {
- sent = std.fmt.bufPrint(&explained, "{s} {s}", .{ @tagName(last.kind), last.arg.slice() }) catch unreachable; // a kind's name and 128 fit 160
+ sent = std.fmt.bufPrint(&explained, "{s} {s}", .{ @tagName(last.kind), last.arg.slice() }) catch unreachable; // an enum's name and a Buf(128) fit 160
if (last_pane != null) at = last.offset;
}
} else if (kind != .status) p.lsp_ask.last = .{ .kind = kind, .arg = .from(arg), .serial = pane.serial, .offset = @intCast(off) };
@@ -275,7 +275,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
defer if (p.fs.failures != failures) p.noteLateFailure(w.pane);
var said: [256]u8 = undefined;
const rows = response orelse
- return p.reportFailure(w.pane, std.fmt.bufPrint(&said, "{s}: the language server did not answer", .{lspWord(w.kind)}) catch unreachable); // short
+ return p.reportFailure(w.pane, std.fmt.bufPrint(&said, "{s}: the language server did not answer", .{lspWord(w.kind)}) catch unreachable); // a literal word and 40 fit 256
// A backend that cannot answer it says why (`@none <why>`).
if (std.mem.startsWith(u8, rows, "@none ")) {
const why = std.mem.trimEnd(u8, rows["@none ".len..], "\n");
@@ -293,7 +293,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
if (applyLspEdits(p, pane, w.revision, edits)) {
var buf: [64]u8 = undefined;
const verb: []const u8 = if (w.kind == .rename) "renamed" else "formatted";
- p.setMessage(w.pane, std.fmt.bufPrint(&buf, "{s} {d} range(s)", .{ verb, edits.len }) catch unreachable); // short
+ p.setMessage(w.pane, std.fmt.bufPrint(&buf, "{s} {d} range(s)", .{ verb, edits.len }) catch unreachable); // a literal and a usize fit 64
}
return;
}
@@ -311,13 +311,13 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
const none: ?[]const u8 = switch (w.kind) {
.completion, .format => null,
.rename => "nothing here to rename",
- .diagnostics, .workspace_diagnostics => return p.setMessage(w.pane, std.fmt.bufPrint(&said, "{s}: none", .{lspWord(w.kind)}) catch unreachable), // short
+ .diagnostics, .workspace_diagnostics => return p.setMessage(w.pane, std.fmt.bufPrint(&said, "{s}: none", .{lspWord(w.kind)}) catch unreachable), // a literal word fits 256
.incoming_calls => "callers not found",
.outgoing_calls => "callees not found",
.hover => "nothing to show: not found",
else => "not found",
};
- if (none) |text| p.reportFailure(w.pane, std.fmt.bufPrint(&said, "{s}: {s}", .{ lspWord(w.kind), text }) catch unreachable); // short literals
+ if (none) |text| p.reportFailure(w.pane, std.fmt.bufPrint(&said, "{s}: {s}", .{ lspWord(w.kind), text }) catch unreachable); // two literals fit 256
return;
}
@@ -399,9 +399,9 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
// renameEdits) are no edits.
const unrenamed = std.mem.count(u8, rows, ", which the server did not rename\n");
p.setMessage(w.pane, if (unrenamed > 0)
- std.fmt.bufPrint(&said_buf, "Rename: previewed, not applied: the server renamed in this file only, and {d} other open file(s) say the name", .{unrenamed}) catch unreachable // 126 at most
+ std.fmt.bufPrint(&said_buf, "Rename: previewed, not applied: the server renamed in this file only, and {d} other open file(s) say the name", .{unrenamed}) catch unreachable // a usize and 106 fit 128
else
- std.fmt.bufPrint(&said_buf, "Rename: {d} edit(s) across files, previewed, not applied", .{nrows}) catch unreachable); // short
+ std.fmt.bufPrint(&said_buf, "Rename: {d} edit(s) across files, previewed, not applied", .{nrows}) catch unreachable); // a usize and 50 fit 128
}
if (panes.Output.traits(from).jumps) {
const result = p.panes[pane.search_pane orelse return] orelse return;