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

Method normalize_fn_ref_value

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

879 /// qualify); `block_argument` is a transparent layer; specials are the
880 /// `method(:sym)` call form and hook-DSL `simple_symbol`s.
881 fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32) {
882 stack_guard!();
883 if depth > 4 {
884 return;
885 }
886 match v.kind() {
887 "block_argument" => {
888 for i in 0..v.named_child_count() {
889 if let Some(c) = v.named_child(i) {
890 self.normalize_fn_ref_value(c, from, depth + 1);
891 }
892 }
893 }
894 "call" => {
895 // `method(:target_cb)` — method field literally `method`, one
896 // simple_symbol argument. Candidate = bare symbol name at the
897 // SYMBOL node (gated at flush on defined-in-file ∪ imports).
898 let Some(method) = v.child_by_field_name("method") else { return };
899 if self.text(method) != "method" {
900 return;
901 }
902 let Some(args) = v.child_by_field_name("arguments") else { return };
903 if args.named_child_count() != 1 {
904 return;
905 }
906 let Some(sym) = args.named_child(0) else { return };
907 if sym.kind() != "simple_symbol" {
908 return;
909 }
910 let name = self.text(sym).strip_prefix(':').unwrap_or(self.text(sym));
911 if !name.is_empty() {
912 self.push_fn_ref_cand(from, name, sym);
913 }
914 }
915 "simple_symbol" => {
916 // Hook-DSL symbols (`before_action :authenticate`) → class-
917 // scoped `this.<sym>` candidates (always flushed).
918 let Some(call) = ruby_enclosing_call(v) else { return };
919 let Some(method) = call.child_by_field_name("method") else { return };
920 if !is_ruby_hook_call(self.text(method)) {
921 return;
922 }
923 let sym = self.text(v).strip_prefix(':').unwrap_or(self.text(v));
924 if !ruby_sym_re().is_match(sym) {
925 return;
926 }
927 let name = format!("this.{sym}");
928 self.push_fn_ref_cand(from, &name, v);
929 }
930 _ => {}
931 }
932 }
933
934 fn push_fn_ref_cand(&mut self, from: u32, name: &str, node: Node) {
935 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