diff options
author | eileencodes <eileencodes@gmail.com> | 2022-10-19 13:23:53 -0400 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2022-10-31 13:39:56 +0900 |
commit | 3391c51effcd61f9a718adf59740661d99f57b5b (patch) | |
tree | c45ce41d5b960638724db4376c0a5a87dab8c0df /ast.c | |
parent | 7ed10abdd97a324583c9b9794088a41a550abcd0 (diff) |
Add `node_id_for_backtrace_location` function
We want to use error highlight with eval'd code, specifically ERB
templates. We're able to recover the generated code for eval'd templates
and can get a parse tree for the ERB generated code, but we don't have a
way to get the node id from the backtrace location. So we can't pass the
right node into error highlight.
This patch gives us an API to get the node id from the backtrace
location so we can find the node in the AST.
Error Highlight PR: https://github.com/ruby/error_highlight/pull/26
Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6593
Diffstat (limited to 'ast.c')
-rw-r--r-- | ast.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -196,6 +196,18 @@ script_lines(VALUE path) } static VALUE +node_id_for_backtrace_location(rb_execution_context_t *ec, VALUE module, VALUE location) +{ + int node_id; + node_id = rb_get_node_id_from_frame_info(location); + if (node_id == -1) { + return Qnil; + } + + return INT2NUM(node_id); +} + +static VALUE ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script_lines, VALUE error_tolerant) { VALUE node, lines = Qnil; |