Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
SyntaxSuggest::CleanDocument#join_groups
join_groups(groups)
lib/syntax_suggest/clean_document.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/syntax_suggest/clean_document.rb, line 266
def join_groups(groups)
groups.each do |lines|
line = lines.first
# Handle the case of multiple groups in a row
# if one is already replaced, move on
next if @document[line.index].empty?
# Join group into the first line
@document[line.index] = CodeLine.new(
lex: lines.map(&:lex).flatten,
line: lines.join,
index: line.index
)
# Hide the rest of the lines
lines[1..].each do |line|
# The above lines already have newlines in them, if add more
# then there will be double newline, use an empty line instead
@document[line.index] = CodeLine.new(line: "", index: line.index, lex: [])
end
end
self
end
Helper method for joining “groups” of lines
Input is expected to be type Array<Array<CodeLine>>
The outer array holds the various “groups” while the inner array holds code lines.
All code lines are “joined” into the first line in their group.
To preserve document size, empty lines are placed in the place of the lines that were “joined”
See also
#join_consecutive!
#join_heredoc!
#clean_sweep
#join_trailing_slash!
also in
4.0 · 3.3 · 3.2