Accept a Prism::ParseResult as input in place of Ruby source text - #476
Merged
Conversation
Service#update_rb_ast(path, parse_result) analyzes a Ruby file from a Prism::ParseResult that the caller has already produced. The path plays the same role as before: it identifies the file, and re-submitting the same path replaces the previous analysis with a diff against it. update_rb_file now reads and parses, then delegates to it. AST.parse_rb is split so the Prism.parse call is separate from building the ProgramNode (AST.build_rb). A ParseResult is required rather than a bare Prism node because comments (`#:` annotations, `typeprof:ignore`) and the Prism::Source used for position encoding are only reachable through it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KHWGVBXpPwoYJ5QsDHLMro
sinsoku
approved these changes
Sep 7, 2026
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
Adds
Service#update_rb_ast(path, parse_result), which analyzes a Ruby file from aPrism::ParseResultthe caller has already produced.update_rb_filenow reads and parses, then delegates to it, so the two entry points share the same diff/replace path.pathplays the same role as before: it is the key the analysis is stored under, and re-submitting the same path replaces the previous analysis.AST.parse_rbis split so thePrism.parsecall is separate from building theProgramNode(AST.build_rb).Why a ParseResult and not a node
Comments (
#:annotations,typeprof:ignore) and thePrism::Sourceused for position encoding are only reachable from theParseResult;Prism::Location#sourceis not public. A bare node or a string is rejected withArgumentError.Motivation
Tools that embed TypeProf and already walk the Prism tree for their own purposes currently have to hand TypeProf the source text and let it parse a second time. This lets them pass the tree they hold.
Tests
test/core/ast_input_test.rb: parity withupdate_rb_file, replacement on re-submission, comments preserved, syntax error returnsfalse, wrong argument types, position encoding.🤖 Generated with Claude Code