class SyntaxSuggest::Capture::BeforeAfterKeywordEnds
显示周围的 kw/end 对
显示这些额外配对的目的是为了解决仅匹配一行可见行时出现的歧义情况。
例如
1 class Dog 2 def bark 4 def eat 5 end 6 end
在这种情况下,可能是第2行缺少一个 `end`,或者第4行是错误添加的额外行(这种情况会发生)。
当我们检测到上述问题时,它会将问题仅显示在第2行
2 def bark
显示“相邻”关键字对可以提供额外的上下文
2 def bark 4 def eat 5 end
示例
lines = BeforeAfterKeywordEnds.new( block: block, code_lines: code_lines ).call()
公共类方法
源代码
# File lib/syntax_suggest/capture/before_after_keyword_ends.rb, line 41 def initialize(code_lines:, block:) @scanner = ScanHistory.new(code_lines: code_lines, block: block) @original_indent = block.current_indent end
公共实例方法
源代码
# File lib/syntax_suggest/capture/before_after_keyword_ends.rb, line 46 def call lines = [] @scanner.scan( up: ->(line, kw_count, end_count) { next true if line.empty? break if line.indent < @original_indent next true if line.indent != @original_indent # If we're going up and have one complete kw/end pair, stop if kw_count != 0 && kw_count == end_count lines << line break end lines << line if line.is_kw? || line.is_end? true }, down: ->(line, kw_count, end_count) { next true if line.empty? break if line.indent < @original_indent next true if line.indent != @original_indent # if we're going down and have one complete kw/end pair,stop if kw_count != 0 && kw_count == end_count lines << line break end lines << line if line.is_kw? || line.is_end? true } ) @scanner.stash_changes lines end