diff --git a/CHANGELOG.md b/CHANGELOG.md index bf4e4454f..0657be76f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ## [Unreleased] +- Fixed some folds in Ruby like `unless`, some blocks, multiline comments, function calls, and different array syntaxes for strings and keywords. + ## 1.114.0 - Prevented an exception raised in the command palette in certain unusual filtering scenarios. diff --git a/packages/language-ruby/grammars/tree-sitter-ruby/folds.scm b/packages/language-ruby/grammars/tree-sitter-ruby/folds.scm index 1caba48dc..a78947bee 100644 --- a/packages/language-ruby/grammars/tree-sitter-ruby/folds.scm +++ b/packages/language-ruby/grammars/tree-sitter-ruby/folds.scm @@ -1,30 +1,38 @@ [ (method) + (comment) (singleton_method) (class) (module) (case) (do_block) + (block) (singleton_class) (lambda) (hash) + (argument_list) (array) - (string_array) (symbol_array) + (string_array) ] @fold ; Fold from `if` to the next `elsif` or `else` in the chain. ((if alternative: [(elsif) (else)]) @fold - (#set! fold.endAt firstNamedChild.nextNamedSibling.nextNamedSibling.startPosition) - (#set! fold.adjustToEndOfPreviousLine true)) + (#set! fold.endAt lastNamedChild.startPosition) + (#set! fold.adjustToEndOfPreviousRow true)) + +((unless + alternative: (else)) @fold + (#set! fold.endAt lastNamedChild.startPosition) + (#set! fold.adjustToEndOfPreviousRow true)) ; Fold from `elsif` to the next `elsif` or `else` in the chain. ((elsif consequence: [(then) (elsif)]) @fold - (#set! fold.endAt firstNamedChild.nextNamedSibling.nextNamedSibling.startPosition) - (#set! fold.adjustToEndOfPreviousLine true)) + (#set! fold.endAt lastNamedChild.startPosition) + (#set! fold.adjustToEndOfPreviousRow true)) ; Fold from `else` to `end`. ((else) @fold @@ -32,3 +40,4 @@ ; A bare `if` without an `else` or `elsif`. (if) @fold +(unless) @fold diff --git a/packages/language-ruby/spec/fixtures/folds.rb b/packages/language-ruby/spec/fixtures/folds.rb index 977407a65..c66bf47ab 100644 --- a/packages/language-ruby/spec/fixtures/folds.rb +++ b/packages/language-ruby/spec/fixtures/folds.rb @@ -1,6 +1,19 @@ class Car < Vehicle # <- fold_begin.class # ^ fold_new_position.class + + class << self + # <- fold_begin.singleton_class + # ^ fold_new_position.singleton_class + end + # <- fold_end.singleton_class + + def self.something + # <- fold_begin.singleton + # ^ fold_new_position.singleton + end + # <- fold_end.singleton + def init(id) # <- fold_begin.method # ^ fold_new_position.method @@ -21,3 +34,72 @@ class Car < Vehicle # <- fold_end.method end # <- fold_end.class + +if something + # <- fold_begin.if + # ^ fold_new_position.if + do_other_thing( + ) +end +# <- fold_end.if + +# if something +# # ^ fold_begin.if_else +# do_other_thing() +# # <- fold_new_position.if_else +# else +# # <- fold_end.if_else +# # # <- fold_begin.else +# # # ^ fold_new_position.else +# do_another() +# end +# # # <- fold_end.else + +unless something + # ^ fold_begin.unless + # ^ fold_new_position.unless + do_other_thing() +end +# <- fold_end.unless + +# unless something +# # ^ fold_begin.unless_with_else +# # ^ fold_new_position.unless_with_else +# do_other_thing() +# else +# # <- fold_end.unless_with_else +# # <- fold_begin.unless_else +# # ^ fold_new_position.unless_else +# we_should_never_do_this() +# end +# # <- fold_end.unless_else + +call_something do + # ^ fold_begin.do_block + # ^ fold_new_position.do_block + a +end +# <- fold_end.do_block + +call_something { + # ^ fold_begin.inline_block + # ^ fold_new_position.inline_block +} +# <- fold_end.inline_block + +multiline_call( + # ^ fold_begin.call + # ^ fold_new_position.call + 10, + 20 +) +# <- fold_end.call + +=begin +# <- fold_begin.multi_comment +# ^ fold_new_position.multi_comment + a + b + c +=end +# <- fold_end.multi_comment