@@ -89,6 +89,8 @@ def build_indentation_deltas
8989 deltas
9090 end
9191
92+ STRUCTURAL_NODES = [ :array , :hash , :class , :module , :sclass , :def , :defs , :if , :while , :until , :for , :case , :kwbegin ]
93+
9294 def receiver_handles_indentation ( node )
9395 if send_node = node . children . first
9496 return false unless send_node . type == :send
@@ -97,12 +99,14 @@ def receiver_handles_indentation(node)
9799 # Only structural node types handle their own indentation.
98100 # These are nodes that create indentation contexts (arrays, hashes, classes, etc.)
99101 # All other receivers (simple references, method calls, literals) should allow block indentation.
100- return [ :array , :hash , :class , :module , :sclass , :def , :defs , :if , :while , :until , :for , :case , :kwbegin ] . include? ( receiver . type )
102+ return STRUCTURAL_NODES . include? ( receiver . type )
101103 end
102104 end
103105
104106 return false
105- end # Recursively walk the AST to build indentation deltas for block structures.
107+ end
108+
109+ # Recursively walk the AST to build indentation deltas for block structures.
106110 # This method identifies nodes that should affect indentation and records the deltas.
107111 # @parameter node [Parser::AST::Node] The current AST node to process.
108112 # @parameter deltas [Hash(Integer, Integer)] The deltas hash to populate.
@@ -119,11 +123,6 @@ def walk_ast_for_indentation(node, deltas, parent = nil)
119123 deltas [ location . last_line ] -= 1
120124 end
121125 end
122- when :array , :hash , :class , :module , :sclass , :def , :defs , :while , :until , :for , :case , :kwbegin
123- if location = node . location
124- deltas [ location . line ] += 1
125- deltas [ location . last_line ] -= 1
126- end
127126 when :if
128127 # We don't want to add deltas for elsif, because it's handled by the if node:
129128 if node . keyword == "if"
@@ -141,6 +140,11 @@ def walk_ast_for_indentation(node, deltas, parent = nil)
141140 end
142141 end
143142 end
143+ when *STRUCTURAL_NODES
144+ if location = node . location
145+ deltas [ location . line ] += 1
146+ deltas [ location . last_line ] -= 1
147+ end
144148 end
145149
146150 node . children . each do |child |
0 commit comments