diff options
Diffstat (limited to 'src/lsp/lsp.zig')
| -rw-r--r-- | src/lsp/lsp.zig | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lsp/lsp.zig b/src/lsp/lsp.zig index 9dd1da5a..7e5595fd 100644 --- a/src/lsp/lsp.zig +++ b/src/lsp/lsp.zig @@ -61,7 +61,18 @@ pub fn query(gpa: std.mem.Allocator, arena: std.mem.Allocator, req: Req, out: *s return b.query(gpa, arena, req, out); } if (req.kind == .explain and backends.len > 0) - try backends[0].query(gpa, arena, req, out); + return backends[0].query(gpa, arena, req, out); + // Nothing asked: said why, where an empty answer would read as nothing + // found. + inline for (backends) |b| if (b.speaks(req.path)) + return none(out, "the language server for this file does not answer it", .{}); + try none(out, "no language server for this file", .{}); +} + +/// The one line a backend answers with when it cannot answer at all, and +/// why: the core says it rather than "nothing found". +pub fn none(out: *std.Io.Writer, comptime fmt: []const u8, args: anytype) std.Io.Writer.Error!void { + try out.print("@none " ++ fmt ++ "\n", args); } // Called on server reader threads; the sink must copy text before returning. @@ -146,3 +157,14 @@ test "LSP encoders report every insufficient output capacity" { } } } + +test "a question no backend answers for a file says why rather than find nothing" { + if (backends.len == 0) return; + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + var buf: [256]u8 = undefined; + var out: std.Io.Writer = .fixed(&buf); + // The in-process ZLS answers no call hierarchy for a .zig file. + try query(std.testing.allocator, arena.allocator(), .{ .kind = .incoming_calls, .path = "/x/main.zig", .source = "", .offset = 0 }, &out); + try std.testing.expectStringStartsWith(out.buffered(), "@none "); +} |
