Skip to content

Commit 993b989

Browse files
committed
update more folding ranges to not include the line with rparen or rbrace
fixes #2218
1 parent e271be4 commit 993b989

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

src/features/folding_range.zig

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,6 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: *const Ast, enc
317317
.call_comma,
318318
.call_one,
319319
.call_one_comma,
320-
=> {
321-
const lparen = tree.nodeMainToken(node);
322-
try builder.add(null, lparen, ast.lastToken(tree, node), .exclusive, .exclusive_ignore_space);
323-
},
324-
325-
// everything after here is mostly untested
326320
.array_init,
327321
.array_init_one,
328322
.array_init_dot_two,
@@ -331,7 +325,6 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: *const Ast, enc
331325
.array_init_dot,
332326
.array_init_dot_comma,
333327
.array_init_comma,
334-
335328
.struct_init,
336329
.struct_init_one,
337330
.struct_init_one_comma,
@@ -340,16 +333,21 @@ pub fn generateFoldingRanges(allocator: std.mem.Allocator, tree: *const Ast, enc
340333
.struct_init_dot,
341334
.struct_init_dot_comma,
342335
.struct_init_comma,
343-
336+
=> {
337+
const start = tree.nodeMainToken(node);
338+
try builder.add(null, start, ast.lastToken(tree, node), .exclusive, .exclusive_ignore_space);
339+
},
344340
.builtin_call,
345341
.builtin_call_comma,
346342
.builtin_call_two,
347343
.builtin_call_two_comma,
348-
349-
.multiline_string_literal,
350344
.error_set_decl,
351-
.test_decl,
352345
=> {
346+
const start = tree.nodeMainToken(node) + 1;
347+
try builder.add(null, start, ast.lastToken(tree, node), .exclusive, .exclusive_ignore_space);
348+
},
349+
350+
.multiline_string_literal => {
353351
try builder.addNode(null, node, .inclusive, .inclusive);
354352
},
355353

tests/lsp_features/folding_range.zig

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,50 @@ test "container decl" {
336336
});
337337
}
338338

339+
test "error set" {
340+
try testFoldingRange(
341+
\\const E = error{
342+
\\ Foo,
343+
\\ Bar,
344+
\\};
345+
, &.{
346+
.{ .startLine = 0, .startCharacter = 16, .endLine = 2, .endCharacter = 8 },
347+
});
348+
}
349+
350+
test "array init" {
351+
try testFoldingRange(
352+
\\const foo = .{
353+
\\ 1,
354+
\\ 2,
355+
\\},
356+
, &.{
357+
.{ .startLine = 0, .startCharacter = 14, .endLine = 2, .endCharacter = 6 },
358+
});
359+
}
360+
361+
test "struct init" {
362+
try testFoldingRange(
363+
\\const foo = .{
364+
\\ .alpha = 1,
365+
\\ .beta = 2,
366+
\\},
367+
, &.{
368+
.{ .startLine = 0, .startCharacter = 14, .endLine = 2, .endCharacter = 14 },
369+
});
370+
}
371+
372+
test "builtin" {
373+
try testFoldingRange(
374+
\\const foo = @as(
375+
\\ u32,
376+
\\ undefined,
377+
\\);
378+
, &.{
379+
.{ .startLine = 0, .startCharacter = 16, .endLine = 2, .endCharacter = 14 },
380+
});
381+
}
382+
339383
test "call" {
340384
try testFoldingRange(
341385
\\extern fn foo(a: bool, b: ?usize) void;

0 commit comments

Comments
 (0)