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

Method normalize_fn_ref_value

codegraph-kernel/src/ruby.rs:914–965  ·  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

912 /// qualify); `block_argument` is a transparent layer; specials are the
913 /// `method(:sym)` call form and hook-DSL `simple_symbol`s.
914 fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32) {
915 stack_guard!();
916 if depth > 4 {
917 return;
918 }
919 match v.kind() {
920 "block_argument" => {
921 for i in 0..v.named_child_count() {
922 if let Some(c) = v.named_child(i) {
923 self.normalize_fn_ref_value(c, from, depth + 1);
924 }
925 }
926 }
927 "call" => {
928 // `method(:target_cb)` — method field literally `method`, one
929 // simple_symbol argument. Candidate = bare symbol name at the
930 // SYMBOL node (gated at flush on defined-in-file ∪ imports).
931 let Some(method) = v.child_by_field_name("method") else { return };
932 if self.text(method) != "method" {
933 return;
934 }
935 let Some(args) = v.child_by_field_name("arguments") else { return };
936 if args.named_child_count() != 1 {
937 return;
938 }
939 let Some(sym) = args.named_child(0) else { return };
940 if sym.kind() != "simple_symbol" {
941 return;
942 }
943 let name = self.text(sym).strip_prefix(':').unwrap_or(self.text(sym));
944 if !name.is_empty() {
945 self.push_fn_ref_cand(from, name, sym);
946 }
947 }
948 "simple_symbol" => {
949 // Hook-DSL symbols (`before_action :authenticate`) → class-
950 // scoped `this.<sym>` candidates (always flushed).
951 let Some(call) = ruby_enclosing_call(v) else { return };
952 let Some(method) = call.child_by_field_name("method") else { return };
953 if !is_ruby_hook_call(self.text(method)) {
954 return;
955 }
956 let sym = self.text(v).strip_prefix(':').unwrap_or(self.text(v));
957 if !ruby_sym_re().is_match(sym) {
958 return;
959 }
960 let name = format!("this.{sym}");
961 self.push_fn_ref_cand(from, &name, v);
962 }
963 _ => {}
964 }
965 }
966
967 fn push_fn_ref_cand(&mut self, from: u32, name: &str, node: Node) {
968 if name.is_empty() || is_stoplisted(name) {

Callers 1

maybe_capture_fn_refsMethod · 0.45

Calls 5

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

Tested by

no test coverage detected