Skip to content

Preserve inline comments inside sig blocks during RBS translation#901

Open
KaanOzkan wants to merge 1 commit into
mainfrom
ko-translate-comment
Open

Preserve inline comments inside sig blocks during RBS translation#901
KaanOzkan wants to merge 1 commit into
mainfrom
ko-translate-comment

Conversation

@KaanOzkan
Copy link
Copy Markdown
Contributor

Comments inside sig do params(...) end blocks were silently dropped because the entire sig node byte range was replaced with the RBS string. Collect any comments within the sig node's range and prepend them to the output before the #: annotation.

Resolves #900

@KaanOzkan KaanOzkan force-pushed the ko-translate-comment branch 4 times, most recently from da8a668 to 36e1207 Compare April 14, 2026 20:51
@KaanOzkan KaanOzkan marked this pull request as ready for review April 14, 2026 21:05
@KaanOzkan KaanOzkan requested a review from a team as a code owner April 14, 2026 21:05
Comment thread test/spoom/sorbet/translate/sorbet_sigs_to_rbs_comments_test.rb
assert_equal(<<~RBS, sorbet_sigs_to_rbs_comments(contents))
# First param
# Second param
#: (Integer a, String b) -> void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should force multi line rendering when we find comments.

Consider this:

params(
  # Some documentation
  a: Integer
).void
def foo(a); end

when translated we get this:

# Some documentation
#: (a) -> void
def foo(a); end

it will look as if the documentation is about foo and not a.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah this makes sense. I think we can either:

  1. Associate comments with parameters in RBI and teach RBSPrinter about outputting it
  2. Keep doing the string post-processing in Spoom, similar to the new add_inline_sig_comments. We could figure out the multiline aspect by looking at the indentation and insert the comment to the relevant line. We'd also need to add a new flag or set max_line_length to 0 for the RBSPrinter to print multiline comment.

I'm leaning towards 1 since we're getting too much into the printing territory. Wdyt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 1. 👍

Comments inside `sig do params(...) end` blocks were silently dropped
because the entire sig node byte range was replaced with the RBS string.
Collect any comments within the sig node's range and prepend them to
the output before the `#:` annotation.
@KaanOzkan KaanOzkan force-pushed the ko-translate-comment branch from 36e1207 to d6b6e91 Compare April 21, 2026 14:02
@KaanOzkan KaanOzkan requested a review from Morriar April 21, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

srb sigs translate removes comments during translation

2 participants