instance method
SyntaxSuggest::ParseBlocksFromIndentLine#each_neighbor_block
each_neighbor_block(target_line) { |block| ... }
lib/syntax_suggest/parse_blocks_from_indent_line.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/syntax_suggest/parse_blocks_from_indent_line.rb, line 37
def each_neighbor_block(target_line)
scan = AroundBlockScan.new(code_lines: code_lines, block: CodeBlock.new(lines: target_line))
.force_add_empty
.force_add_hidden
.scan_while { |line| line.indent >= target_line.indent }
neighbors = scan.code_block.lines
block = CodeBlock.new(lines: neighbors)
if neighbors.length <= 2 || block.valid?
yield block
else
until neighbors.empty?
lines = [neighbors.pop]
while (block = CodeBlock.new(lines: lines)) && block.invalid? && neighbors.any?
lines.prepend neighbors.pop
end
yield block if block
end
end
end
Builds blocks from bottom up