Skip to content

Fix Prism comment JSON deserialization (comment_type / embdoc)#97

Open
sorafujitani wants to merge 2 commits intomainfrom
cursor/fix-prism-comment-json
Open

Fix Prism comment JSON deserialization (comment_type / embdoc)#97
sorafujitani wants to merge 2 commits intomainfrom
cursor/fix-prism-comment-json

Conversation

@sorafujitani
Copy link
Copy Markdown
Owner

@sorafujitani sorafujitani commented Apr 4, 2026

Description

Ruby PrismBridge が返すトップレベルコメント JSON を、Rust の PrismComment で正しく解釈するよう修正しました。comment_type キーと embdoc / inline などの値を扱い、旧形式の type キーも読み取ります。

Motivation

PrismComment#[serde(rename = "type")] のため、実際のペイロード comment_type と不一致で種別が常にデフォルト化されていました。また embdocinline は列挙子に存在せず、該当コメントを含むソースで JSON 全体のデシリアライズが失敗し得ました。

Fixes #
Related to #

Changes

  • ext/rfmt/src/parser/prism_adapter.rs: comment_type を主キーに、type をエイリアス化。柔軟な deserialize_prism_comment_type とユニットテストを追加。
  • spec/rfmt_spec.rb: =begin / =end 付きソースの回帰テストを追加。
  • .claude/plans/*.md: プロジェクト内の計画メモを追加。
  • .direnv/flake-profile 系: 追跡されていたシンボリックリンクを削除。

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactoring (no functional changes, improves code quality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Test addition/update

Testing

  • All existing tests pass (bundle exec rspec)
  • Rust tests pass (cd ext/rfmt && cargo test)
  • Added new tests for new functionality
  • Manually tested with the following scenarios:
    • nix develop + bash --noprofile --norc 上で bundle exec rake compile / bundle exec rspec
    • embdoc 付きソースの Rfmt.formatPrism.parse が成功することを確認

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have updated documentation if needed
  • My changes generate no new warnings (cargo clippy)
  • I have added tests that prove my fix/feature works

Screenshots / Examples

Before
Prism JSON の comment_type: "embdoc" 等でデシリアライズ失敗、または種別が常に Line 扱いになる可能性
After
comment_type / type の両方を受理し、embdoc → Block、inline → Line としてパースが完了

Additional Notes

  • ローカルで bundle がシステム Ruby に取られる場合は、nix develop 後に bash --noprofile --norc -c 'bundle exec …' で実行すると安定します。

Note

Medium Risk
Medium risk because it changes AST/comment deserialization, which can impact how comments are classified and therefore emitted during formatting; mitigated by defaulting unknown values and adding targeted tests.

Overview
Ensures top-level Prism comments from Ruby PrismBridge deserialize correctly by switching PrismComment to read comment_type (with type as an alias) and adding a custom deserializer that maps values like embdoc and inline to internal comment kinds without failing on unknown values.

Adds Rust unit coverage for both the new and legacy comment payloads, and adds an RSpec regression test that formatting Ruby with =begin/=end comments completes successfully and remains parseable. Also adds multiple .claude/plans/*.md planning notes and removes committed .direnv/flake-profile* link artifacts.

Reviewed by Cursor Bugbot for commit b1c7292. Bugbot is set up for automated code reviews on this repo. Configure here.

Align PrismComment with PrismBridge keys; map embdoc/inline safely.
Add RSpec for embdoc sources and Rust tests.
@sorafujitani sorafujitani marked this pull request as ready for review April 4, 2026 03:27
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b1c7292. Configure here.

bundle exec rake compile
bundle exec rspec
bundle exec rspec spec/conditional_formatting_spec.rb
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Plan files committed despite gitignore exclusion intent

Low Severity

Ten .claude/plans/*.md files containing internal development notes for unrelated issues (#71, #73, #85, #86, #87, etc.) are committed. The project's .gitignore uses .claude/*.md to exclude personal memos, but this glob doesn't match subdirectory files like .claude/plans/*.md. The .claude/README.md explicitly labels .md files as "個人メモ" to be excluded, and plans/ is not in the whitelisted directories (agents/, commands/, skills/). The gitignore pattern likely needs .claude/**/*.md to catch these.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b1c7292. Configure here.

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.

1 participant