Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/features/folding_range.zig
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,6 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: *const Ast, enc
.call_comma,
.call_one,
.call_one_comma,
=> {
const lparen = tree.nodeMainToken(node);
try builder.add(null, lparen, ast.lastToken(tree, node), .exclusive, .exclusive_ignore_space);
},

// everything after here is mostly untested
.array_init,
.array_init_one,
.array_init_dot_two,
Expand All @@ -331,7 +325,6 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: *const Ast, enc
.array_init_dot,
.array_init_dot_comma,
.array_init_comma,

.struct_init,
.struct_init_one,
.struct_init_one_comma,
Expand All @@ -340,16 +333,21 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: *const Ast, enc
.struct_init_dot,
.struct_init_dot_comma,
.struct_init_comma,

=> {
const start = tree.nodeMainToken(node);
try builder.add(null, start, ast.lastToken(tree, node), .exclusive, .exclusive_ignore_space);
},
.builtin_call,
.builtin_call_comma,
.builtin_call_two,
.builtin_call_two_comma,

.multiline_string_literal,
.error_set_decl,
.test_decl,
=> {
const start = tree.nodeMainToken(node) + 1;
try builder.add(null, start, ast.lastToken(tree, node), .exclusive, .exclusive_ignore_space);
},

.multiline_string_literal => {
try builder.addNode(null, node, .inclusive, .inclusive);
},

Expand Down
44 changes: 44 additions & 0 deletions tests/lsp_features/folding_range.zig
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,50 @@ test "container decl" {
});
}

test "error set" {
try testFoldingRange(
\\const E = error{
\\ Foo,
\\ Bar,
\\};
, &.{
.{ .startLine = 0, .startCharacter = 16, .endLine = 2, .endCharacter = 8 },
});
}

test "array init" {
try testFoldingRange(
\\const foo = .{
\\ 1,
\\ 2,
\\},
, &.{
.{ .startLine = 0, .startCharacter = 14, .endLine = 2, .endCharacter = 6 },
});
}

test "struct init" {
try testFoldingRange(
\\const foo = .{
\\ .alpha = 1,
\\ .beta = 2,
\\},
, &.{
.{ .startLine = 0, .startCharacter = 14, .endLine = 2, .endCharacter = 14 },
});
}

test "builtin" {
try testFoldingRange(
\\const foo = @as(
\\ u32,
\\ undefined,
\\);
, &.{
.{ .startLine = 0, .startCharacter = 16, .endLine = 2, .endCharacter = 14 },
});
}

test "call" {
try testFoldingRange(
\\extern fn foo(a: bool, b: ?usize) void;
Expand Down