fix: コメント付き module/def/メソッド呼び出しの round-trip 不具合#338
Merged
Conversation
When multiple blocks start on the same line with equal range, findBlockForLine now prefers statement blocks over input (value) blocks. This prevents user comments from being attached to data_variable blocks instead of the parent procedures_call, which corrupted @ruby:lvar: metadata and caused variable names to become @_name_1_. Also robustified data_variable's @ruby:lvar: extraction to use regex match instead of startsWith, as a defensive measure. Refs #336 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove DefNode from isBeforeContainer check so comments before method definitions are attached to the procedures_definition block instead of becoming workspace comments. This keeps method comments inside the class. Also robustified @ruby:module_source: matching with multiline flag to handle cases where user comments are prepended to metadata. Refs #336 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Create @ruby:module:ModuleName workspace comments for comments before module definitions, similar to @ruby:class for classes. The code generator detects these comments and places them before the module code. Also fixed finishTargets module deduplication regex to capture preceding comment lines when extracting module...end blocks. Refs #336 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds a comprehensive round-trip test using the exact reproduction case from issue #336, verifying all three bugs are fixed together: - Module comment before module definition - Def comment inside class before method - Variable reference preserved with comments Refs #336 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/fix/comment-roundtrip-bugs-336/ |
github-actions Bot
pushed a commit
that referenced
this pull request
Mar 18, 2026
…oundtrip-bugs-336 fix: コメント付き module/def/メソッド呼び出しの round-trip 不具合
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.
Summary
Ruby → Blocks → Ruby ラウンドトリップにおける3つのコメント関連不具合を修正。
findBlockForLineが input ブロック(data_variable)を優先してしまい、ユーザーコメントが@ruby:lvar:メタデータを破壊 →greet(name)がgreet(@_name_1_)に変化。statement ブロックを優先するよう修正isBeforeContainerにDefNodeが含まれ、def 前のコメントが workspace コメントとしてクラス外に出力される →DefNodeを除外しprocedures_definitionブロックに関連付けotherCommentsとして module コードの後に配置される →@ruby:module:ModuleNameworkspace コメントを導入し、コメントをモジュールの前に配置Changes Made
packages/scratch-gui/src/lib/ruby-to-blocks-converter/index.jslineStartBlockMap構築時に input ブロックより statement ブロックを優先(Bug 3)isBeforeContainerからDefNodeを除外(Bug 2)ModuleNodeのcontainerNodeRangesにモジュール名を保存(Bug 1)@ruby:module:ModuleNameメタデータを付加(Bug 1)packages/scratch-gui/src/lib/ruby-generator/data.js@ruby:lvar:メタデータ抽出をstartsWith→match()に変更(防御的修正)packages/scratch-gui/src/lib/ruby-generator/procedure.js@ruby:module_source:マッチングに multiline フラグ追加packages/scratch-gui/src/lib/ruby-generator/code-finisher.js@ruby:module:workspace コメント検出・モジュールコード前にユーザーコメント出力finishTargetsのモジュール抽出正規表現で preceding コメント行を含むよう修正Implementation Steps
findBlockForLineのブロック優先度修正 +@ruby:lvar:ロバスト化Test Coverage
ruby-roundtrip-comment-bugs.test.jsRelated Issues
Fixes #336