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

Method try_visit_hook

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

Returns true when the hook handled the node (mixin call or module). The DISPATCHER then runs scan_fn_ref_subtree on the handled subtree — the source of the module multiply-capture quirk (scan runs with the module already POPPED, so candidates re-attribute to the outer scope).

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

407 /// the source of the module multiply-capture quirk (scan runs with the
408 /// module already POPPED, so candidates re-attribute to the outer scope).
409 fn try_visit_hook(&mut self, node: Node<'t>) -> bool {
410 stack_guard!();
411 let kind = node.kind();
412 if kind == "call" && node.child_by_field_name("receiver").is_none() {
413 if let Some(method) = node.child_by_field_name("method") {
414 if matches!(self.text(method), "include" | "extend" | "prepend") {
415 let args = node.child_by_field_name("arguments").or_else(|| {
416 (0..node.named_child_count())
417 .filter_map(|i| node.named_child(i))
418 .find(|c| c.kind() == "argument_list")
419 });
420 // (nodeStack is never empty — the file node is pushed.)
421 if let Some(args) = args {
422 let parent = self.top_row();
423 let implements = edge_kind_index("implements").unwrap();
424 let line = self.line_of(node);
425 let col = self.col_of(node);
426 for i in 0..args.named_child_count() {
427 let Some(arg) = args.named_child(i) else { continue };
428 // `Mod` is constant, `Foo::Bar` is scope_resolution;
429 // `extend self` / dynamic args are skipped. Unlike
430 // every other extraction ref, the hook sets
431 // `filePath: ctx.filePath` — flagged on the wire.
432 if matches!(arg.kind(), "constant" | "scope_resolution") {
433 let name_ref = self.arena.put(self.text(arg));
434 self.tables.push_ref_flagged(
435 &RefRow {
436 from_idx: parent,
437 kind: implements,
438 line,
439 column: col,
440 reference_name: name_ref,
441 candidates: NONE_STR,
442 from_id_str: NONE_STR,
443 },
444 REF_FLAG_FILE_PATH,
445 );
446 }
447 }
448 return true;
449 }
450 // no args node → hook declines (falls to extractImport → nothing)
451 }
452 }
453 }
454
455 if kind != "module" {
456 return false;
457 }
458 let Some(name_node) = node.child_by_field_name("name") else { return false };
459 // `module A::B` keeps the scope_resolution text verbatim as the name.
460 let name = self.text(name_node).to_string();
461 let Some(row) = self.create_node("module", &name, node, Extra::default()) else {
462 return false;
463 };
464 self.stack.push(Scope { row, kind: "module", name });
465 if let Some(body) = node.child_by_field_name("body") {
466 for i in 0..body.named_child_count() {

Callers 1

visit_nodeMethod · 0.45

Calls 11

edge_kind_indexFunction · 0.85
push_ref_flaggedMethod · 0.80
pushMethod · 0.80
putMethod · 0.65
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
line_ofMethod · 0.45
col_ofMethod · 0.45
create_nodeMethod · 0.45
visit_nodeMethod · 0.45

Tested by

no test coverage detected