This class is responsible for taking a code block that exists at a far indentaion and then iteratively increasing the block so that it captures everything within the same indentation block.
def dog puts "bow" puts "wow" end
block = BlockExpand.new
(code_lines: code_lines)
.call(CodeBlock.new(lines: code_lines[1]))
puts block.to_s # => puts “bow”
puts "wow"
Once a code block has captured everything at a given indentation level then it will expand to capture surrounding indentation.
block = BlockExpand.new
(code_lines: code_lines)
.call(block)
block.to_s # => def dog
puts "bow" puts "wow" end
Class Methods
lib/syntax_suggest/block_expand.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/block_expand.rb, line 34
def initialize(code_lines:)
@code_lines = code_lines
end
No documentation available
Instance Methods
lib/syntax_suggest/block_expand.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/block_expand.rb, line 38
def call(block)
if (next_block = expand_neighbors(block))
return next_block
end
expand_indent(block)
end
No documentation available
lib/syntax_suggest/block_expand.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/block_expand.rb, line 46
def expand_indent(block)
AroundBlockScan.new(code_lines: @code_lines, block: block)
.skip(:hidden?)
.stop_after_kw
.scan_adjacent_indent
.code_block
end
No documentation available
lib/syntax_suggest/block_expand.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/block_expand.rb, line 54
def expand_neighbors(block)
expanded_lines = AroundBlockScan.new(code_lines: @code_lines, block: block)
.skip(:hidden?)
.stop_after_kw
.scan_neighbors
.scan_while { |line| line.empty? } # Slurp up empties
.lines
if block.lines == expanded_lines
nil
else
CodeBlock.new(lines: expanded_lines)
end
end
No documentation available
#
lib/syntax_suggest/block_expand.rb
View on GitHub
# File tmp/rubies/ruby-3.2.0/lib/syntax_suggest/block_expand.rb, line 70
def inspect
"#<SyntaxSuggest::CodeBlock:0x0000123843lol >"
end
Managable rspec errors