Skip to content

Use #source_range when available for Prism.find - #4234

Open
eregon wants to merge 1 commit into
ruby:mainfrom
eregon:find-source_range
Open

eregon wants to merge 1 commit into
ruby:mainfrom
eregon:find-source_range

Conversation

@eregon

@eregon eregon commented Sep 23, 2026

Copy link
Copy Markdown
Member
  • This is more accurate than using the line and is a portable API between Ruby implementations.
  • This also works in --parser=parse.y mode.
  • I also tried to use #syntax_tree but that fails 2 tests as it returns the CallNode instead of BlockNode for blocks. Additionally, #syntax_tree emits many warnings when running the test suite:
    syntax_tree: a prism gem other than the default gem is loaded; the result may not correspond exactly to the compiled code

I have tested locally and this works fine on TruffleRuby 40 which implements source_range.

Fixes #4066

* This is more accurate than using the line and is a portable API between Ruby implementations.
* This also works in --parser=parse.y mode.
* I also tried to use #syntax_tree but that fails 2 tests as it returns the CallNode instead of BlockNode for blocks.
  Additionally, #syntax_tree emits many warnings when running the test suite:
  syntax_tree: a prism gem other than the default gem is loaded; the result may not correspond exactly to the compiled code
@Earlopain

Copy link
Copy Markdown
Collaborator

What is the use-case of Prism.find now that ruby has #syntax_tree (other that this works on earlier versions)? This has not been released yet, can we just drop it? Especially since there are differences between the results, which I would not expect.

Also, we really should get rid of that warning

@Earlopain

Copy link
Copy Markdown
Collaborator

This branch has not been deployed

No deployments
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.

Prism.find can return the wrong node on older Ruby versions

2 participants