diff options
Diffstat (limited to 'src/lsp/Ask.zig')
| -rw-r--r-- | src/lsp/Ask.zig | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/lsp/Ask.zig b/src/lsp/Ask.zig index 6b5dd8c8..b00a3384 100644 --- a/src/lsp/Ask.zig +++ b/src/lsp/Ask.zig @@ -45,22 +45,22 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) // file, place and argument -- from wherever it is run. 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: [160]u8 = undefined; + var said: pardes.Kind.Buf(160) = .{}; if (!lsp.supports.contains(kind)) - return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: no language server here answers it", .{lspWord(kind)}) catch unreachable); // a word and 45 fit 160 + return p.reportFailure(id, said.print("{s}: no language server here answers it", .{lspWord(kind)})); const pane = p.panes[id] orelse return; if (kind != .status) { const f = pane.file orelse - return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: only a file's pane asks a language server", .{lspWord(kind)}) catch unreachable); // a word and 45 fit 160 + return p.reportFailure(id, said.print("{s}: only a file's pane asks a language server", .{lspWord(kind)})); if (f.output != null) - return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: only a file's pane asks a language server", .{lspWord(kind)}) catch unreachable); // a word and 45 fit 160 + return p.reportFailure(id, said.print("{s}: only a file's pane asks a language server", .{lspWord(kind)})); } - if (arg.len > 128) return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: its argument is at most 128 bytes", .{lspWord(kind)}) catch unreachable); // a word and 45 fit 160 + if (arg.len > 128) return p.reportFailure(id, said.print("{s}: its argument is at most 128 bytes", .{lspWord(kind)})); if (kind == .rename) { 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[0..@min(arg.len, 128)]}) catch unreachable); // 128 and 19 fit 160 + return p.reportFailure(id, said.print("Rename: {s} is no name", .{arg})); } var off = if (pane.file) |f| modal.offsetAt(f.content, .{ .row = @intCast(@max(0, pane.body.cur_row)), @@ -83,17 +83,17 @@ 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[0..@min(arg.len, 128)] }) catch unreachable); // a literal word, 128 and 18 fit 160 + return p.reportFailure(id, said.print("{s}: no {s} in this file", .{ lspWord(kind), arg })); arg = ""; } // Lspwhy asks the last query again, narrated: its kind and argument, // at its place when asked from its pane. None yet: a definition. - var explained: [160]u8 = undefined; + var explained: pardes.Kind.Buf(160) = .{}; var sent = arg; 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; // an enum's name and a Buf(128) fit 160 + sent = explained.print("{s} {s}", .{ @tagName(last.kind), last.arg.slice() }); 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) }; @@ -273,13 +273,13 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { // its pane -- fails a 9P write that asked it too. const failures = p.fs.failures; defer if (p.fs.failures != failures) p.noteLateFailure(w.pane); - var said: [256]u8 = undefined; + var said: pardes.Kind.Buf(256) = .{}; 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); // a literal word and 40 fit 256 + return p.reportFailure(w.pane, said.print("{s}: the language server did not answer", .{lspWord(w.kind)})); // 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"); - return p.reportFailure(w.pane, std.fmt.bufPrint(&said, "{s}: {s}", .{ lspWord(w.kind), why[0..@min(why.len, 200)] }) catch unreachable); // 200 fit 256 + return p.reportFailure(w.pane, said.print("{s}: {s}", .{ lspWord(w.kind), why })); } // Index's answer is its indexer's command line, run in a command // pane (lsp_client.indexCommand). @@ -291,9 +291,9 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { const fallback: ?[]const u8 = if (w.kind == .rename) w.arg.slice() else null; if (parseLspEdits(p, rows, fallback)) |edits| { if (applyLspEdits(p, pane, w.revision, edits)) { - var buf: [64]u8 = undefined; + var buf: pardes.Kind.Buf(64) = .{}; 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); // a literal and a usize fit 64 + p.setMessage(w.pane, buf.print("{s} {d} range(s)", .{ verb, edits.len })); } 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), // a literal word fits 256 + .diagnostics, .workspace_diagnostics => return p.setMessage(w.pane, said.print("{s}: none", .{lspWord(w.kind)})), .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); // two literals fit 256 + if (none) |text| p.reportFailure(w.pane, said.print("{s}: {s}", .{ lspWord(w.kind), text })); return; } @@ -347,8 +347,8 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { else => false, }; if (listing and !p.look_missed) { - var where: [300]u8 = undefined; - p.setMessage(v.active, std.fmt.bufPrint(&where, "{s}: the one, {s}", .{ lspWord(w.kind), place[0..@min(place.len, 240)] }) catch unreachable); // 240 fit 300 + var where: pardes.Kind.Buf(300) = .{}; + p.setMessage(v.active, where.print("{s}: the one, {s}", .{ lspWord(w.kind), place })); } return; } @@ -394,14 +394,14 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void { }; } if (w.kind == .rename) { - var said_buf: [128]u8 = undefined; + var said_buf: pardes.Kind.Buf(128) = .{}; // Rows that only name a file the server left alone (lsp_client // 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 // a usize and 106 fit 128 + said_buf.print("Rename: previewed, not applied: the server renamed in this file only, and {d} other open file(s) say the name", .{unrenamed}) else - std.fmt.bufPrint(&said_buf, "Rename: {d} edit(s) across files, previewed, not applied", .{nrows}) catch unreachable); // a usize and 50 fit 128 + said_buf.print("Rename: {d} edit(s) across files, previewed, not applied", .{nrows})); } if (panes.Output.traits(from).jumps) { const result = p.panes[pane.search_pane orelse return] orelse return; |
