Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d32cf62
Introduce BalanceHeuristicExpand
schneems Jan 12, 2022
7324ef1
New direction BlockNode and IndentTree
schneems Jan 17, 2022
ddcc646
Initial tree building
schneems Jan 26, 2022
3682b6b
Handle invalid nodes
schneems Jan 26, 2022
a7d0fe2
Tree building perf commit
schneems Jan 26, 2022
6fd4e36
Reintroduce and fix InsertionSort for performance
schneems Jan 26, 2022
24cde0f
Fix missing deleted logic
schneems Jan 26, 2022
32eb0b3
Build tree recording
schneems Jan 27, 2022
20656d7
Slightly faster initial sorting
schneems Jan 27, 2022
b1acaf5
Tiny perf change to CodeLine#initialize
schneems Jan 27, 2022
763dec4
Remove unused code
schneems Jan 27, 2022
4ab2b70
Pull out inner/outer nodes
schneems Jan 27, 2022
5ba79c0
Rename @inner to @parents
schneems Jan 27, 2022
60d796e
Figure out search algorithm
schneems Jan 27, 2022
083e733
REXE test case
schneems Jan 28, 2022
c260450
Add more test cases
schneems Jan 28, 2022
22f9fc0
Add another test
schneems Jan 28, 2022
f2b8878
Fix problem with my logic for "inner/outer" check
schneems Jan 28, 2022
b7a6c65
Add misindentation test
schneems Jan 29, 2022
01c2b8c
Refactor decision logic into node
schneems Jan 29, 2022
1fa20e1
Initial idea to search by "diagnosing" a node
schneems Jan 31, 2022
16a109b
Fix BlockNode.from_parents above/below
schneems Feb 1, 2022
72cd93e
Fix BlockNode.from_parents that have 1 parent
schneems Feb 1, 2022
c5dbd27
Handle multiple case
schneems Feb 1, 2022
db85b5b
First indent tree search
schneems Feb 2, 2022
1a34697
Standardrb --fix
schneems Feb 3, 2022
6185b90
More search cases
schneems Feb 3, 2022
036373b
Follow multiple errors with IndentSearch
schneems Feb 5, 2022
f977054
Implement tracing on new search
schneems Feb 6, 2022
62bff09
Move IndentSearch to a proper file
schneems Feb 7, 2022
b8a1549
Add missing frozen string magic comment
schneems Feb 7, 2022
4301fab
Move BlockRecorder to proper file
schneems Feb 7, 2022
53eb266
Document IndentSearch
schneems Feb 7, 2022
ea6986e
Move journey to proper file
schneems Feb 7, 2022
ccd9816
Document and refactor IndentTree
schneems Feb 7, 2022
93bab24
Document BlockNode and update BlockDocument docs
schneems Feb 8, 2022
f3a83a5
Refactor logic to Diagnose class
schneems Feb 8, 2022
e06af0c
Fix problem with one bad internal node
schneems Feb 8, 2022
a666da7
Fix block reporter
schneems Feb 8, 2022
011e8a0
Diagnose docs, rename problems & fix one edge case
schneems Feb 8, 2022
70087ed
Refactor Diagnose into smaller methods & rename
schneems Feb 8, 2022
745dc3b
Move diagnose node to its own file
schneems Feb 8, 2022
194ee1b
standardrb --fix
schneems Feb 8, 2022
e0256d1
Finish extraction of Diagnose logic
schneems Feb 8, 2022
c0d8625
Remove unused BalanceHueristicExpand
schneems Feb 9, 2022
e5a70a9
WIP Integration with One failing test
schneems Feb 9, 2022
fc872fb
WIP 8 total failing tests
schneems Feb 9, 2022
026aa1b
WIP Initial BlockNodeContext
schneems Feb 10, 2022
60b4ed3
Update block building
schneems Feb 15, 2022
ee2c9fd
WIP WIP WIP????
schneems Feb 16, 2022
2303179
WIPPPPPPPPPPPPPPPPPPPPPPPPPP
schneems Feb 16, 2022
be9b4c4
WIP
schneems May 20, 2022
02285d2
Fix nested pseudo pair case
schneems Jun 4, 2022
ef535d5
192 examples, 2 failures, 1 pending
schneems Jun 7, 2022
fc7a62c
Check if one node can be pruned from multiple
schneems Jun 7, 2022
91b94a4
Move test out of ruby CLI
schneems Jun 8, 2022
c3b30da
Porting examples from existing tests
schneems Jun 8, 2022
4dfa1b2
This is a difficult problem
schneems Jul 26, 2022
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
Prev Previous commit
Next Next commit
standardrb --fix
  • Loading branch information
schneems committed May 20, 2022
commit 194ee1b02b984c3e0b16d7ba95a8e5e7df5161d7
3 changes: 1 addition & 2 deletions lib/dead_end/block_node.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module DeadEnd

# A core data structure
#
# A block node keeps a reference to the block above it
Expand Down Expand Up @@ -157,7 +156,7 @@ def fork_invalid
def handle_multiple
@diagnose.next.first
end
alias :remove_pseudo_pair :handle_multiple
alias_method :remove_pseudo_pair, :handle_multiple

def split_leaning
@diagnose.next.first
Expand Down
3 changes: 1 addition & 2 deletions lib/dead_end/block_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module DeadEnd
#
# This class allows for tracing the algorithm
class BlockRecorder

# Convienece constructor for building a BlockRecorder given
# a directory object.
#
Expand All @@ -14,7 +13,7 @@ class BlockRecorder
#
# Multiple different processes may be logging to the same
# directory, so writing to a subdir is recommended
def self.from_dir(dir, subdir: , code_lines: )
def self.from_dir(dir, subdir:, code_lines:)
if dir == DEFAULT_VALUE
dir = ENV["DEAD_END_RECORD_DIR"] || ENV["DEBUG"] ? DeadEnd.record_dir("tmp") : nil
end
Expand Down
31 changes: 15 additions & 16 deletions lib/dead_end/diagnose_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def call
invalid = get_invalid
return self if invalid.empty?

if @problem == :multiple_invalid_parents
@next = invalid.map {|b| BlockNode.from_blocks([b]) }
@next = if @problem == :multiple_invalid_parents
invalid.map { |b| BlockNode.from_blocks([b]) }
else
@next = [ BlockNode.from_blocks(invalid) ]
[BlockNode.from_blocks(invalid)]
end

self
Expand Down Expand Up @@ -111,7 +111,7 @@ def call
if left && right && invalid.length >= 3 && BlockNode.from_blocks([left, right]).valid?
@problem = :invalid_inside_split_pair

invalid.reject! {|x| x == left || x == right }
invalid.reject! { |x| x == left || x == right }

# If the left/right was not mapped properly or we've accidentally got a :multiple_invalid_parents
# we can get a false positive, double check the invalid lines fully capture the problem
Expand All @@ -120,12 +120,11 @@ def call
without_lines: invalid.flat_map(&:lines)
)

return invalid
invalid
end
end
end


# ## (:remove_pseudo_pair) Handle else/ensure case
#
# Example:
Expand Down Expand Up @@ -168,19 +167,19 @@ def call
return false if above.nil? || below.nil?

if invalid.reject! { |block|
b = BlockNode.from_blocks([above, block, below])
b.leaning == :equal && b.valid?
}
b = BlockNode.from_blocks([above, block, below])
b.leaning == :equal && b.valid?
}

if invalid.any?
@problem = :remove_pseudo_pair
return invalid
invalid
else

invalid = block.parents.select(&:invalid?)
if (b = invalid.detect { |b| BlockNode.from_blocks([above, invalid - [b] , below].flatten).valid? })
if (b = invalid.detect { |b| BlockNode.from_blocks([above, invalid - [b], below].flatten).valid? })
@problem = :extract_from_multiple
return [b]
[b]
end
end
end
Expand All @@ -189,10 +188,10 @@ def call
# We couldn't detect any special cases, either return 1 or N invalid nodes
private def diagnose_one_or_more_parents
invalid = block.parents.select(&:invalid?)
if invalid.length > 1
@problem = :multiple_invalid_parents
@problem = if invalid.length > 1
:multiple_invalid_parents
else
@problem = :one_invalid_parent
:one_invalid_parent
end

invalid
Expand All @@ -201,7 +200,7 @@ def call
private def diagnose_self
if block.parents.empty?
@problem = :self
return []
[]
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dead_end/indent_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module DeadEnd
class IndentSearch
attr_reader :finished

def initialize(tree: , record_dir: DEFAULT_VALUE)
def initialize(tree:, record_dir: DEFAULT_VALUE)
@tree = tree
@root = tree.root
@finished = []
Expand Down Expand Up @@ -57,7 +57,7 @@ def call
end
end

@finished.sort_by! {|j| j.node.starts_at }
@finished.sort_by! { |j| j.node.starts_at }

self
end
Expand Down
1 change: 0 additions & 1 deletion lib/dead_end/indent_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def initialize(document:, record_dir: DEFAULT_VALUE)
@code_lines = document.code_lines
@last_length = Float::INFINITY


@recorder = BlockRecorder.from_dir(record_dir, subdir: "build_tree", code_lines: @code_lines)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/indent_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def initialize(arguments:, block:, location:)
search = IndentSearch.new(tree: tree).call

expect(search.finished.first.node.to_s).to eq(<<~'EOM')
def on_args_add(arguments, argument)
def on_args_add(arguments, argument)
EOM
end

Expand Down
13 changes: 6 additions & 7 deletions spec/unit/indent_tree_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ class Cow
node = tree.root

expect(node.diagnose).to eq(:one_invalid_parent)
node = node.next_invalid
node = node.next_invalid

expect(node.diagnose).to eq(:self)
expect(node.to_s).to eq(<<~'EOM')
end # two
EOM
end


it "ambiguous kw" do
source = <<~'EOM'
class Cow
Expand All @@ -46,7 +45,7 @@ def speak
node = tree.root
expect(node.parents.length).to eq(2)
expect(node.diagnose).to eq(:one_invalid_parent)
node = node.next_invalid
node = node.next_invalid

expect(node.diagnose).to eq(:self)
expect(node.to_s).to eq(<<~'EOM')
Expand Down Expand Up @@ -74,7 +73,7 @@ class Buffalo
# expect(node.parents.length).to eq(2)

expect(node.diagnose).to eq(:multiple_invalid_parents)
forks = node.fork_invalid
forks = node.fork_invalid

node = forks.first

Expand Down Expand Up @@ -120,9 +119,9 @@ def speak
expect(node.diagnose).to eq(:invalid_inside_split_pair)
node = node.split_leaning
expect(node.to_s).to eq(<<~'EOM')
puts (
else
puts }
puts (
else
puts }
EOM

expect(node.diagnose).to eq(:remove_pseudo_pair)
Expand Down