Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions lib/dead_end/code_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,15 @@ def push(block, name:)
frontier << block
end

# Removes the block without putting it back in the frontier
def sweep(block:, name:)
record(block: block, name: name)

block.lines.each(&:mark_invisible)
frontier.register_indent_block(block)
end

# Parses the most indented lines into blocks that are marked
# and added to the frontier
def visit_new_blocks
max_indent = frontier.next_indent_line&.indent

while (line = frontier.next_indent_line) && (line.indent == max_indent)

@parse_blocks_from_indent_line.each_neighbor_block(frontier.next_indent_line) do |block|
record(block: block, name: "add")

block.mark_invisible if block.valid?
push(block, name: "add")
end
end
Expand Down
17 changes: 11 additions & 6 deletions lib/dead_end/parse_blocks_from_indent_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ def each_neighbor_block(target_line)

neighbors = scan.code_block.lines

until neighbors.empty?
lines = [neighbors.pop]
while (block = CodeBlock.new(lines: lines)) && block.invalid? && neighbors.any?
lines.prepend neighbors.pop
end
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
yield block if block
end
end
end
end
Expand Down