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

Method try_visit_hook

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

383 /// the source of the module multiply-capture quirk (scan runs with the
384 /// module already POPPED, so candidates re-attribute to the outer scope).
385 fn try_visit_hook(&mut self, node: Node<'t>) -> bool {
386 stack_guard!();
387 let kind = node.kind();
388 if kind == "call" && node.child_by_field_name("receiver").is_none() {
389 if let Some(method) = node.child_by_field_name("method") {
390 if matches!(self.text(method), "include" | "extend" | "prepend") {
391 let args = node.child_by_field_name("arguments").or_else(|| {
392 (0..node.named_child_count())
393 .filter_map(|i| node.named_child(i))
394 .find(|c| c.kind() == "argument_list")
395 });
396 // (nodeStack is never empty — the file node is pushed.)
397 if let Some(args) = args {
398 let parent = self.top_row();
399 let implements = edge_kind_index("implements").unwrap();
400 let line = self.line_of(node);
401 let col = self.col_of(node);
402 for i in 0..args.named_child_count() {
403 let Some(arg) = args.named_child(i) else { continue };
404 // `Mod` is constant, `Foo::Bar` is scope_resolution;
405 // `extend self` / dynamic args are skipped. Unlike
406 // every other extraction ref, the hook sets
407 // `filePath: ctx.filePath` — flagged on the wire.
408 if matches!(arg.kind(), "constant" | "scope_resolution") {
409 let name_ref = self.arena.put(self.text(arg));
410 self.tables.push_ref_flagged(
411 &RefRow {
412 from_idx: parent,
413 kind: implements,
414 line,
415 column: col,
416 reference_name: name_ref,
417 candidates: NONE_STR,
418 from_id_str: NONE_STR,
419 },
420 REF_FLAG_FILE_PATH,
421 );
422 }
423 }
424 return true;
425 }
426 // no args node → hook declines (falls to extractImport → nothing)
427 }
428 }
429 }
430
431 if kind != "module" {
432 return false;
433 }
434 let Some(name_node) = node.child_by_field_name("name") else { return false };
435 // `module A::B` keeps the scope_resolution text verbatim as the name.
436 let name = self.text(name_node).to_string();
437 let Some(row) = self.create_node("module", &name, node, Extra::default()) else {
438 return false;
439 };
440 self.stack.push(Scope { row, kind: "module", name });
441 if let Some(body) = node.child_by_field_name("body") {
442 for i in 0..body.named_child_count() {

Callers 1

visit_nodeMethod · 0.45

Calls 10

edge_kind_indexFunction · 0.85
push_ref_flaggedMethod · 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