File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+
96110fn testDocumentSymbol (source : []const u8 , expected : []const u8 ) ! void {
97111 var ctx : Context = try .init ();
98112 defer ctx .deinit ();
You can’t perform that action at this time.
0 commit comments