MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / normalize_fn_ref_value

Method normalize_fn_ref_value

codegraph-kernel/src/ruby.rs:934–983  ·  view source on GitHub ↗

normalizeValue for RUBY_SPEC: idTypes EMPTY (bare identifiers never qualify); `block_argument` is a transparent layer; specials are the `method(:sym)` call form and hook-DSL `simple_symbol`s.

(&mut self, v: Node<'t>, from: u32, depth: u32)

Source from the content-addressed store, hash-verified

932 /// qualify); `block_argument` is a transparent layer; specials are the
933 /// `method(:sym)` call form and hook-DSL `simple_symbol`s.
934 fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32) {
935 stack_guard!();
936 if depth > 4 {
937 return;
938 }
939 match v.kind() {
940 "block_argument" => {
941 for c in v.named_children(&mut v.walk()) {
942 self.normalize_fn_ref_value(c, from, depth + 1);
943 }
944 }
945 "call" => {
946 // `method(:target_cb)` — method field literally `method`, one
947 // simple_symbol argument. Candidate = bare symbol name at the
948 // SYMBOL node (gated at flush on defined-in-file ∪ imports).
949 let Some(method) = v.child_by_field_name("method") else { return };
950 if self.text(method) != "method" {
951 return;
952 }
953 let Some(args) = v.child_by_field_name("arguments") else { return };
954 if args.named_child_count() != 1 {
955 return;
956 }
957 let Some(sym) = args.named_child(0) else { return };
958 if sym.kind() != "simple_symbol" {
959 return;
960 }
961 let name = self.text(sym).strip_prefix(':').unwrap_or(self.text(sym));
962 if !name.is_empty() {
963 self.push_fn_ref_cand(from, name, sym);
964 }
965 }
966 "simple_symbol" => {
967 // Hook-DSL symbols (`before_action :authenticate`) → class-
968 // scoped `this.<sym>` candidates (always flushed).
969 let Some(call) = ruby_enclosing_call(v) else { return };
970 let Some(method) = call.child_by_field_name("method") else { return };
971 if !is_ruby_hook_call(self.text(method)) {
972 return;
973 }
974 let sym = self.text(v).strip_prefix(':').unwrap_or(self.text(v));
975 if !ruby_sym_re().is_match(sym) {
976 return;
977 }
978 let name = format!("this.{sym}");
979 self.push_fn_ref_cand(from, &name, v);
980 }
981 _ => {}
982 }
983 }
984
985 fn push_fn_ref_cand(&mut self, from: u32, name: &str, node: Node) {
986 if name.is_empty() || is_stoplisted(name) {

Callers 1

maybe_capture_fn_refsMethod · 0.45

Calls 6

ruby_enclosing_callFunction · 0.85
is_ruby_hook_callFunction · 0.85
ruby_sym_reFunction · 0.85
textMethod · 0.65
walkMethod · 0.45
push_fn_ref_candMethod · 0.45

Tested by

no test coverage detected