diff options
author | KaĆque Kandy Koga <kaiquekandykoga@gmail.com> | 2021-10-25 18:32:40 -0300 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2021-12-03 00:56:43 +0900 |
commit | 6b64e788234c19560070192927ae7b35b19b4587 (patch) | |
tree | e53651530421756a71250449bccf43e4affd8915 /lib/irb/ruby-lex.rb | |
parent | d486286f1d8fa01356498792b368c46fe9619d09 (diff) | |
download | ruby-6b64e788234c19560070192927ae7b35b19b4587.tar.gz |
[ruby/irb] Examine indentation of in keyword when trying to type include
Use in_keyword_case_scope?
Return fast
https://github.com/ruby/irb/commit/8acc7f8dc7
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r-- | lib/irb/ruby-lex.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 751d6ec526..f2069a2b5f 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -693,8 +693,12 @@ class RubyLex unless t.state.allbits?(Ripper::EXPR_LABEL) spaces_of_nest.push(spaces_at_line_head) end - when 'else', 'elsif', 'ensure', 'when', 'in' + when 'else', 'elsif', 'ensure', 'when' corresponding_token_depth = spaces_of_nest.last + when 'in' + if in_keyword_case_scope? + corresponding_token_depth = spaces_of_nest.last + end when 'end' if is_first_printable_of_line corresponding_token_depth = spaces_of_nest.pop @@ -837,5 +841,21 @@ class RubyLex heredoc_tokens = @tokens.select { |t| [:on_heredoc_beg, :on_heredoc_end].include?(t.event) } heredoc_tokens[-1]&.event == :on_heredoc_beg end + + def in_keyword_case_scope? + kw_tokens = @tokens.select { |t| t.event == :on_kw && ['case', 'for', 'end'].include?(t.tok) } + counter = 0 + kw_tokens.reverse.each do |t| + if t.tok == 'case' + return true if counter.zero? + counter += 1 + elsif t.tok == 'for' + counter += 1 + elsif t.tok == 'end' + counter -= 1 + end + end + false + end end # :startdoc: |