diff options
Diffstat (limited to 'lib/syntax_suggest/capture_code_context.rb')
-rw-r--r-- | lib/syntax_suggest/capture_code_context.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/syntax_suggest/capture_code_context.rb b/lib/syntax_suggest/capture_code_context.rb index 6439af4dde..1f232cfae3 100644 --- a/lib/syntax_suggest/capture_code_context.rb +++ b/lib/syntax_suggest/capture_code_context.rb @@ -1,6 +1,14 @@ # frozen_string_literal: true module SyntaxSuggest + module Capture + end +end + +require_relative "capture/falling_indent_lines" +require_relative "capture/before_after_keyword_ends" + +module SyntaxSuggest # Turns a "invalid block(s)" into useful context # # There are three main phases in the algorithm: @@ -18,7 +26,7 @@ module SyntaxSuggest # they can't add extra data that's not present. # # In the case of known ambiguious cases, this class adds context - # back to the ambiguitiy so the programmer has full information. + # back to the ambiguity so the programmer has full information. # # Beyond handling these ambiguities, it also captures surrounding # code context information: @@ -55,6 +63,10 @@ module SyntaxSuggest capture_falling_indent(block) end + sorted_lines + end + + def sorted_lines @lines_to_output.select!(&:not_empty?) @lines_to_output.uniq! @lines_to_output.sort! @@ -76,12 +88,11 @@ module SyntaxSuggest # end # end # - # def capture_falling_indent(block) - AroundBlockScan.new( + Capture::FallingIndentLines.new( block: block, code_lines: @code_lines - ).on_falling_indent do |line| + ).call do |line| @lines_to_output << line end end @@ -116,9 +127,10 @@ module SyntaxSuggest def capture_before_after_kws(block) return unless block.visible_lines.count == 1 - around_lines = AroundBlockScan.new(code_lines: @code_lines, block: block) - .start_at_next_line - .capture_neighbor_context + around_lines = Capture::BeforeAfterKeywordEnds.new( + code_lines: @code_lines, + block: block + ).call around_lines -= block.lines @@ -140,7 +152,7 @@ module SyntaxSuggest # However due to https://github.com/ruby/syntax_suggest/issues/32 # the problem line will be identified as: # - # ❯ class Dog # 1 + # > class Dog # 1 # # Because lines 2, 3, and 4 are technically valid code and are expanded # first, deemed valid, and hidden. We need to un-hide the matching end @@ -200,7 +212,7 @@ module SyntaxSuggest # # the problem line will be identified as: # - # ❯ end # 4 + # > end # 4 # # This happens because lines 1, 2, and 3 are technically valid code and are expanded # first, deemed valid, and hidden. We need to un-hide the matching keyword on |