diff --git a/src/features/inlay_hints.zig b/src/features/inlay_hints.zig index 448bf6548..cdfa6e745 100644 --- a/src/features/inlay_hints.zig +++ b/src/features/inlay_hints.zig @@ -237,6 +237,24 @@ fn writeVariableDeclHint(builder: *Builder, decl_node: Ast.Node.Index) !void { ); if (type_str.len == 0) return; + // Restrict whitespace to only one space at a time. + var reduced_type_str = std.ArrayList(u8).init(builder.arena); + // Overallocates by a small amount if whitespace is reduced, but it should be fine. + try reduced_type_str.ensureTotalCapacity(type_str.len); + var skip = false; + for (type_str) |char| { + if (char == '\n' or char == ' ') { + if (!skip) { + try reduced_type_str.append(' '); + } + skip = true; + continue; + } + skip = false; + try reduced_type_str.append(char); + } + type_str = reduced_type_str.items; + try builder.hints.append(builder.arena, .{ .index = offsets.tokenToLoc(tree, hint.ast.mut_token + 1).end, .label = try std.fmt.allocPrint(builder.arena, ": {s}", .{ diff --git a/tests/lsp_features/inlay_hints.zig b/tests/lsp_features/inlay_hints.zig index bb4a68e71..908dff179 100644 --- a/tests/lsp_features/inlay_hints.zig +++ b/tests/lsp_features/inlay_hints.zig @@ -112,6 +112,28 @@ test "inlayhints - var decl" { \\ } \\} , .Type); + try testInlayHints( + \\ fn thing(a: u32, b: i32) struct { + \\ a: u32, + \\ b: i32, + \\ c: struct { + \\ d: usize, + \\ e: []const u8, + \\ }, + \\ } { + \\ return .{ + \\ .a = a, + \\ .b = b, + \\ .c = .{ + \\ .d = 0, + \\ .e = "Testing", + \\ } + \\ }; + \\ } + \\ + \\ var a = thing(10, -4); + \\ _ = a; + , .Type); } fn testInlayHints(source: []const u8, kind: types.InlayHintKind) !void {