Draft
Conversation
When converting RBS comments to Sorbet sigs, the line numbers of method definitions were shifting because multi-line RBS comments were being replaced with single-line sigs without padding. This fix adds blank lines after generated sigs to match the line count of the original RBS comments, ensuring method definitions stay on their original line numbers. Fixes #787
paracycle
reviewed
Feb 17, 2026
| padding = "\n" * (original_lines - replacement_lines) | ||
| replacement_string + padding | ||
| else | ||
| replacement_string |
Member
There was a problem hiding this comment.
What happens if original_lines < replacement_lines? Could that ever happen? Should we handle that explicitly and raise if that is not expected?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #787
Problem
When using
Spoom::Sorbet::Translate.rbs_comments_to_sorbet_sig, line numbers weren't preserved. Multi-line RBS comments were replaced with single-line sigs, causing method definitions to shift up in the file. This made errors and stacktraces misalign with the original source.Example:
Solution
Added a
preserve_line_numbershelper that:Result:
Testing
test_translate_to_rbi_multiline_sigsto expect preserved line numbersChanges
lib/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs.rb:preserve_line_numbershelper methodrewrite_defto use line preservationvisit_attrto use line preservationtest/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb:test_translate_to_rbi_multiline_sigsexpectations