instance method
SyntaxSuggest::CaptureCodeContext#capture_before_after_kws
capture_before_after_kws(block)
lib/syntax_suggest/capture_code_context.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/syntax_suggest/capture_code_context.rb, line 127
def capture_before_after_kws(block)
return unless block.visible_lines.count == 1
around_lines = Capture::BeforeAfterKeywordEnds.new(
code_lines: @code_lines,
block: block
).call
around_lines -= block.lines
@lines_to_output.concat(around_lines)
end
Shows surrounding kw/end pairs
The purpose of showing these extra pairs is due to cases of ambiguity when only one visible line is matched.
For example:
1 class Dog 2 def bark 4 def eat 5 end 6 end
In this case either line 2 could be missing an end or line 4 was an extra line added by mistake (it happens).
When we detect the above problem it shows the issue as only being on line 2
2 def bark
Showing “neighbor” keyword pairs gives extra context:
2 def bark 4 def eat 5 end
See also
#call
#capture_falling_indent
.new
#capture_first_kw_end_same_indent
also in
3.4 · 3.3 · 3.2