diff --git a/lib/spoom/rbs.rb b/lib/spoom/rbs.rb index 7067d42e..e6abc5c8 100644 --- a/lib/spoom/rbs.rb +++ b/lib/spoom/rbs.rb @@ -75,9 +75,17 @@ def node_rbs_comments(node) continuation_comments = [] #: Array[Prism::Comment] + last_line = node.location.start_line + comments.each do |comment| string = comment.slice + comment_line = comment.location.end_line + + break if comment_line < last_line - 1 + + last_line = comment_line + if string.start_with?("# @") string = string.delete_prefix("#").strip res.annotations << Annotation.new(string, comment.location) diff --git a/test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb b/test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb index f9d385d6..4d608927 100644 --- a/test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb +++ b/test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb @@ -426,6 +426,26 @@ def test_translate_to_rbi_defs_within_send RBS end + def test_translate_to_rbi_selects_right_comments + contents = <<~RB + #: -> void + + class Foo + #: -> void + + #: -> void + + class << self + #: -> void + + def bar; end + end + end + RB + + assert_equal(contents, rbs_comments_to_sorbet_sigs(contents)) + end + private #: (String, ?max_line_length: Integer?) -> String