Skip to content

Commit

Permalink
Generate folding ranges for empty container types (#1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
llogick authored Oct 1, 2023
1 parent 8d5eb78 commit aa47752
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/features/folding_range.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},

Expand Down
9 changes: 9 additions & 0 deletions tests/lsp_features/folding_range.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aa47752

Please sign in to comment.