Class: Prism::NodeFind::RubyVMBacktraceLocationFind

Inherits:
Find
  • Object
show all
Defined in:
lib/prism/node_find.rb,
sig/generated/prism/node_find.rbs

Overview

Finds the AST node for a Thread::Backtrace::Location using the node_id from the backtrace location.

Instance Method Summary collapse

Instance Method Details

#find(location) ⇒ Node?

Find the node for the given backtrace location using node_id.

: (Thread::Backtrace::Location location) -> Node?

Parameters:

  • location (Thread::Backtrace::Location)

Returns:



113
114
115
116
117
118
119
120
121
# File 'lib/prism/node_find.rb', line 113

def find(location)
  file = location.absolute_path || location.path
  return unless (result = parse_file(file))
  return unless RubyVM::AbstractSyntaxTree.respond_to?(:node_id_for_backtrace_location)

  node_id = RubyVM::AbstractSyntaxTree.node_id_for_backtrace_location(location)

  result.value.find { |node| node.node_id == node_id }
end