fix: stop Rails Routes from stalling on cast errors and unsaved files#98
Merged
Conversation
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>
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.
Background
GitHub issue #94 reports that clicking
Rails Routeson RubyMine 2026.1.1 stalls atLoading...and logsClassCastException: RConstantImpl cannot be cast to RContainer. Routes parsing aborts entirely when Ruby's StubIndex returns a non-RContainerelement (for example a constant referenced byinclude) for a name that the existing code cast unconditionally.While addressing that, an adjacent issue is also fixed: when the user edits
config/routes.rband clicksRails Routeswithout saving, the externalrails routesprocess reads the on-disk file and ignores the in-editor changes.Summary
RContainerStubIndex results so Rails Routes no longer stalls on the reported cast error.rails routes, so the command sees the latest route edits.Changes
PsiUtil.findClassOrModule()now requires anis RContainersmart cast in addition to the name match. Non-RContainerentries from the StubIndex (such asRConstantImpl) are skipped, andnullis returned when no class/module is found. The three existing call sites already toleratenull/ non-matching containers.RailsRouteAction.actionPerformed()callsFileDocumentManager.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 insideRoutesTask/RoutesPreflight, which run inside coroutine read actions and external-process IO contexts not suited for write commands.Notes
PsiUtil.findClassOrModule()is included. ABasePlatformTestCaseattempt failed in setUp because Ruby plugin'sBundleConfigService.getInstance()returnsnullon the Light Test Fixture, which blocks creation of*.rbPSI files. Setting up a Ruby-aware test fixture is tracked separately as a follow-up so the regression test can be added later.Testing
./gradlew checkroutes.rb(includingModule.new-style routing) thatRails Routesno longer throwsClassCastExceptionand the routes table loads. Also verified that editingconfig/routes.rbwithout saving and then clickingRails Routesreflects the latest changes.