类 SyntaxSuggest::Capture::FallingIndentLines

显示代码周围的上下文,通过“下降”缩进提供

如果这是原始代码行

class OH
  def hello
    it "foo" do
  end
end

而这是捕获的行

it "foo" do

它将生成其周围的上下文

class OH
  def hello
  end
end

示例

FallingIndentLines.new(
    block: block,
    code_lines: @code_lines
).call do |line|
  @lines_to_output << line
end

公共类方法

new(code_lines:, block:) 点击切换源代码
# File lib/syntax_suggest/capture/falling_indent_lines.rb, line 36
def initialize(code_lines:, block:)
  @lines = nil
  @scanner = ScanHistory.new(code_lines: code_lines, block: block)
  @original_indent = block.current_indent
end

公共实例方法

call(&yieldable) 点击切换源代码
# File lib/syntax_suggest/capture/falling_indent_lines.rb, line 42
def call(&yieldable)
  last_indent_up = @original_indent
  last_indent_down = @original_indent

  @scanner.commit_if_changed
  @scanner.scan(
    up: ->(line, _, _) {
      next true if line.empty?

      if line.indent < last_indent_up
        yieldable.call(line)
        last_indent_up = line.indent
      end
      true
    },
    down: ->(line, _, _) {
      next true if line.empty?

      if line.indent < last_indent_down
        yieldable.call(line)
        last_indent_down = line.indent
      end
      true
    }
  )
  @scanner.stash_changes
end