From aa47752f5b77a16cea2e06dc59971fce130dec95 Mon Sep 17 00:00:00 2001 From: nullptrdevs <16590917+nullptrdevs@users.noreply.github.com> Date: Sat, 30 Sep 2023 23:09:21 -0700 Subject: [PATCH] Generate folding ranges for empty container types (#1474) --- src/features/folding_range.zig | 5 +++++ tests/lsp_features/folding_range.zig | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/features/folding_range.zig b/src/features/folding_range.zig index 68a14b459..a28ebb6f8 100644 --- a/src/features/folding_range.zig +++ b/src/features/folding_range.zig @@ -244,6 +244,11 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: Ast, encoding: } const end_tok = ast.lastToken(tree, node); try builder.add(null, start_tok, end_tok, .exclusive, .exclusive); + } else { // no members (yet), ie `const T = type {};` + var start_tok = tree.firstToken(node); + while(token_tags[start_tok] != .l_brace) start_tok += 1; + const end_tok = ast.lastToken(tree, node); + try builder.add(null, start_tok, end_tok, .exclusive, .exclusive); } }, diff --git a/tests/lsp_features/folding_range.zig b/tests/lsp_features/folding_range.zig index 30bda21fd..bc724512c 100644 --- a/tests/lsp_features/folding_range.zig +++ b/tests/lsp_features/folding_range.zig @@ -12,6 +12,15 @@ test "foldingRange - empty" { try testFoldingRange("", &.{}); } +test "foldingRange - container type without members" { + try testFoldingRange( + \\const S = struct { + \\}; + , &.{ + .{ .startLine = 0, .startCharacter = 18, .endLine = 1, .endCharacter = 0 }, + }); +} + test "foldingRange - doc comment" { try testFoldingRange( \\/// hello