Skip to content

Commit 622ad8e

Browse files
committed
give placeholder name to document symbols for decls with empty names
1 parent 83ae7b1 commit 622ad8e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/features/document_symbol.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,11 @@ fn convertSymbolsInternal(
203203
const to: []types.DocumentSymbol = symbol_buffer.items[prev_len..];
204204

205205
for (from, to) |symbol, *out| {
206+
// LSP spec requires that a symbol name is not empty or consisting only of whitespace
207+
const name_is_empty = symbol.name.len == 0 or
208+
std.mem.indexOfNone(u8, symbol.name, &std.ascii.whitespace) == null;
206209
out.* = .{
207-
.name = symbol.name,
210+
.name = if (name_is_empty) "<unnamed>" else symbol.name,
208211
.detail = symbol.detail,
209212
.kind = symbol.kind,
210213
// will be set later through the mapping below

tests/lsp_features/document_symbol.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ test "nested struct with self" {
9393
);
9494
}
9595

96+
test "empty decl names return non-empty document symbol" {
97+
try testDocumentSymbol(
98+
\\test "" {}
99+
\\test " " {}
100+
\\const @"" = 0;
101+
\\const @" " = 0;
102+
,
103+
\\Method <unnamed>
104+
\\Method <unnamed>
105+
\\Constant <unnamed>
106+
\\Constant <unnamed>
107+
);
108+
}
109+
96110
fn testDocumentSymbol(source: []const u8, expected: []const u8) !void {
97111
var ctx: Context = try .init();
98112
defer ctx.deinit();

0 commit comments

Comments
 (0)