Skip to content

fix: stop Rails Routes from stalling on cast errors and unsaved files#98

Merged
thinkAmi merged 2 commits into
epic/support_ide_2026from
fix/cast_rcontainer
May 10, 2026
Merged

fix: stop Rails Routes from stalling on cast errors and unsaved files#98
thinkAmi merged 2 commits into
epic/support_ide_2026from
fix/cast_rcontainer

Conversation

@thinkAmi
Copy link
Copy Markdown
Owner

Background

GitHub issue #94 reports that clicking Rails Routes on RubyMine 2026.1.1 stalls at Loading... and logs ClassCastException: RConstantImpl cannot be cast to RContainer. Routes parsing aborts entirely when Ruby's StubIndex returns a non-RContainer element (for example a constant referenced by include) for a name that the existing code cast unconditionally.

While addressing that, an adjacent issue is also fixed: when the user edits config/routes.rb and clicks Rails Routes without saving, the external rails routes process reads the on-disk file and ignores the in-editor changes.

Summary

  • Skip non-RContainer StubIndex results so Rails Routes no longer stalls on the reported cast error.
  • Save unsaved editor buffers before running rails routes, so the command sees the latest route edits.

Changes

  • PsiUtil.findClassOrModule() now requires an is RContainer smart cast in addition to the name match. Non-RContainer entries from the StubIndex (such as RConstantImpl) are skipped, and null is returned when no class/module is found. The three existing call sites already tolerate null / non-matching containers.
  • RailsRouteAction.actionPerformed() calls FileDocumentManager.getInstance().saveAllDocuments() at the action entry point before launching the routes task. The save is intentionally placed in the action (EDT, write-safe context) rather than inside RoutesTask / RoutesPreflight, which run inside coroutine read actions and external-process IO contexts not suited for write commands.

Notes

  • No new unit test for PsiUtil.findClassOrModule() is included. A BasePlatformTestCase attempt failed in setUp because Ruby plugin's BundleConfigService.getInstance() returns null on the Light Test Fixture, which blocks creation of *.rb PSI files. Setting up a Ruby-aware test fixture is tracked separately as a follow-up so the regression test can be added later.
  • The scope is intentionally limited to the action entry point and the StubIndex result handling. Broader cleanup of the routes parsing pipeline is not part of this PR.

Testing

  • ./gradlew check
  • Manual: verified on the reporter's routes.rb (including Module.new-style routing) that Rails Routes no longer throws ClassCastException and the routes table loads. Also verified that editing config/routes.rb without saving and then clicking Rails Routes reflects the latest changes.

thinkAmi and others added 2 commits May 10, 2026 22:28
The StubIndex can return non-RContainer elements such as RConstantImpl
(e.g. when an `include SomeConstant` references a non-module constant).
The previous unconditional `as RContainer` cast threw ClassCastException
in that case and stalled the entire rails routes parsing.

Replace it with an `is RContainer` smart cast so non-container matches
are skipped and `null` is returned when no class/module is found.

Tests:
- ./gradlew check

🤖 Generated with https://claude.ai/code

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
rails routes is an external process that reads files from disk, so any
in-editor edits to config/routes.rb (or related Ruby sources) that have
not been written out yet will not be reflected in the result.

Call FileDocumentManager.saveAllDocuments() at the action entry point,
before launching the routes task, so the external process always sees
the up-to-date contents.

Tests:
- ./gradlew check

🤖 Generated with https://claude.ai/code

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@thinkAmi thinkAmi merged commit 44238f1 into epic/support_ide_2026 May 10, 2026
4 checks passed
@thinkAmi thinkAmi deleted the fix/cast_rcontainer branch May 10, 2026 14:13
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