Skip to content

Commit 73e9543

Browse files
committed
Fixed folds for Ruby
1 parent 7d2d876 commit 73e9543

File tree

2 files changed

+95
-4
lines changed

2 files changed

+95
-4
lines changed
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
[
22
(method)
3+
(comment)
34
(singleton_method)
45
(class)
56
(module)
67
(case)
78
(do_block)
9+
(block)
810
(singleton_class)
911
(lambda)
1012
(hash)
13+
(argument_list)
1114
(array)
1215
] @fold
1316

1417

1518
; Fold from `if` to the next `elsif` or `else` in the chain.
1619
((if
1720
alternative: [(elsif) (else)]) @fold
18-
(#set! fold.endAt firstNamedChild.nextNamedSibling.nextNamedSibling.startPosition)
19-
(#set! fold.adjustToEndOfPreviousLine true))
21+
(#set! fold.endAt lastNamedChild.startPosition)
22+
(#set! fold.adjustToEndOfPreviousRow true))
23+
24+
((unless
25+
alternative: (else)) @fold
26+
(#set! fold.endAt lastNamedChild.startPosition)
27+
(#set! fold.adjustToEndOfPreviousRow true))
2028

2129
; Fold from `elsif` to the next `elsif` or `else` in the chain.
2230
((elsif
2331
consequence: [(then) (elsif)]) @fold
24-
(#set! fold.endAt firstNamedChild.nextNamedSibling.nextNamedSibling.startPosition)
25-
(#set! fold.adjustToEndOfPreviousLine true))
32+
(#set! fold.endAt lastNamedChild.startPosition)
33+
(#set! fold.adjustToEndOfPreviousRow true))
2634

2735
; Fold from `else` to `end`.
2836
((else) @fold
2937
(#set! fold.endAt endPosition))
3038

3139
; A bare `if` without an `else` or `elsif`.
3240
(if) @fold
41+
(unless) @fold

packages/language-ruby/spec/fixtures/folds.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
class Car < Vehicle
22
# <- fold_begin.class
33
# ^ fold_new_position.class
4+
5+
class << self
6+
# <- fold_begin.singleton_class
7+
# ^ fold_new_position.singleton_class
8+
end
9+
# <- fold_end.singleton_class
10+
11+
def self.something
12+
# <- fold_begin.singleton
13+
# ^ fold_new_position.singleton
14+
end
15+
# <- fold_end.singleton
16+
417
def init(id)
518
# <- fold_begin.method
619
# ^ fold_new_position.method
@@ -21,3 +34,72 @@ def init(id)
2134
# <- fold_end.method
2235
end
2336
# <- fold_end.class
37+
38+
if something
39+
# <- fold_begin.if
40+
# ^ fold_new_position.if
41+
do_other_thing(
42+
)
43+
end
44+
# <- fold_end.if
45+
46+
# if something
47+
# # ^ fold_begin.if_else
48+
# do_other_thing()
49+
# # <- fold_new_position.if_else
50+
# else
51+
# # <- fold_end.if_else
52+
# # # <- fold_begin.else
53+
# # # ^ fold_new_position.else
54+
# do_another()
55+
# end
56+
# # # <- fold_end.else
57+
58+
unless something
59+
# ^ fold_begin.unless
60+
# ^ fold_new_position.unless
61+
do_other_thing()
62+
end
63+
# <- fold_end.unless
64+
65+
# unless something
66+
# # ^ fold_begin.unless_with_else
67+
# # ^ fold_new_position.unless_with_else
68+
# do_other_thing()
69+
# else
70+
# # <- fold_end.unless_with_else
71+
# # <- fold_begin.unless_else
72+
# # ^ fold_new_position.unless_else
73+
# we_should_never_do_this()
74+
# end
75+
# # <- fold_end.unless_else
76+
77+
call_something do
78+
# ^ fold_begin.do_block
79+
# ^ fold_new_position.do_block
80+
a
81+
end
82+
# <- fold_end.do_block
83+
84+
call_something {
85+
# ^ fold_begin.inline_block
86+
# ^ fold_new_position.inline_block
87+
}
88+
# <- fold_end.inline_block
89+
90+
multiline_call(
91+
# ^ fold_begin.call
92+
# ^ fold_new_position.call
93+
10,
94+
20
95+
)
96+
# <- fold_end.call
97+
98+
=begin
99+
# <- fold_begin.multi_comment
100+
# ^ fold_new_position.multi_comment
101+
a
102+
b
103+
c
104+
=end
105+
# <- fold_end.multi_comment

0 commit comments

Comments
 (0)