-
Notifications
You must be signed in to change notification settings - Fork 177
Add Prism.node_for(Method|UnboundMethod|Proc) to get a Prism node for a callable #3808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Looks like Proc generated by |
dd02f75 to
5d510f5
Compare
|
The 2.7 failure is quite annoying: https://github.com/ruby/prism/actions/runs/20211767571/job/58018650394?pr=3808 |
This is something we should probably talk about sometime in the future. It was added for the convenience of rubocop as far as I'm aware and I appreciate that this happened. But I do not want to keep these long EOL versions supported forever. For now I would just put this in a separate file like you said. You shoudl be able to use the version-specific gemfile with |
24bdf87 to
3c0b91c
Compare
@tompng Do you mean: does not have a |
Implemented. |
|
Looking at things like |
966dda3 to
eafdef7
Compare
|
I found that {Method,UnboundMethod,Proc}#source_location returns columns in bytes and not in characters. EDIT: It also means |
lib/prism/parse_result.rb
Outdated
| end_offset = parse_result.source.line_to_byte_offset(end_line) + end_column | ||
| start_byte_column = start_offset - parse_result.source.line_start(start_offset) | ||
|
|
||
| found = root.tunnel(start_line, start_byte_column).reverse.find do |node| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rfind would be nice here but of course it's only RUby 4+.
I guess we could do a polyfill but for this case I doubt it matters, most of the time is not spent here but in creating the Ruby objects for the AST, there are typically only a few nodes returned by tunnel.
|
Re the test-all failure, I'll fix it, makes it clear test-unit |
|
For reference, this won't be available (at least in Ruby 4.0) unfortunately https://bugs.ruby-lang.org/issues/21783#note-8 |
|
@eregon we've marked this as blocked until and unless the source location thing gets resolved. Another option is requesting an official node_id API. Is that something you would consider implementing in TruffleRuby? |
… a callable * See https://bugs.ruby-lang.org/issues/21005 and https://bugs.ruby-lang.org/issues/20999 * Stub source_location for older Rubies in NodeForTest. * Move out the inline method definition for Ruby 2.7.
* By comparing byte offsets which folds 3 branches into 1. * Also avoids allocation of Location objects.
|
ruby/ruby#15580 is merged so this is unblocked now :) |
|
The CI was green before updating to latest CRuby 4.1: https://github.com/ruby/prism/actions/runs/20605030946/attempts/2?pr=3808 Upgrading to sexp_processor-4.17.5 should fix that. |
and https://bugs.ruby-lang.org/issues/20999