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

Method extract_class_members

codegraph-kernel/src/rlang.rs:486–548  ·  view source on GitHub ↗

extractClassMembers (r.ts:110-163): arguments in source order with a positional counter — ggproto's 2nd positional identifier and `inherit`/`contains` named args become `extends` refs (from the CLASS row, positioned at the VALUE node); named function_definition args and `list(…)` entries become methods. Non-method argument subtrees are NEVER visited (`representation(…)`, `signature(…)` invisible).

(&mut self, class_call: Node<'t>, class_row: u32)

Source from the content-addressed store, hash-verified

484 /// `list(…)` entries become methods. Non-method argument subtrees are
485 /// NEVER visited (`representation(…)`, `signature(…)` invisible).
486 fn extract_class_members(&mut self, class_call: Node<'t>, class_row: u32) {
487 stack_guard!();
488 let args = match class_call.child_by_field_name("arguments") {
489 Some(a) => a,
490 None => return,
491 };
492 let mut positional = 0u32;
493 let mut cursor = args.walk();
494 let arg_nodes: Vec<Node<'t>> = args.named_children(&mut cursor).collect();
495 for arg in arg_nodes {
496 if arg.kind() != "argument" {
497 continue;
498 }
499 let arg_name = arg.child_by_field_name("name");
500 let value = arg.child_by_field_name("value");
501 let arg_name = match arg_name {
502 None => {
503 positional += 1;
504 if positional == 2 {
505 if let Some(v) = value {
506 if v.kind() == "identifier" {
507 let parent = self.text(v).to_string();
508 self.push_ref_at(class_row, &parent, "extends", v);
509 }
510 }
511 }
512 continue;
513 }
514 Some(n) => n,
515 };
516 let arg_name_text = self.text(arg_name);
517 // R6 `inherit = Parent` / S4 `contains = "Parent"` — a falsy
518 // resolution (`inherit = pkg::Parent`, empty string) emits nothing.
519 if (arg_name_text == "inherit" || arg_name_text == "contains") && value.is_some() {
520 if let Some(parent) = self.literal_or_identifier(value) {
521 if !parent.is_empty() {
522 let parent = parent.to_string();
523 self.push_ref_at(class_row, &parent, "extends", value.unwrap());
524 }
525 }
526 continue;
527 }
528 // Direct named function argument (ggproto methods).
529 if let Some(v) = value {
530 if v.kind() == "function_definition" {
531 self.emit_method_arg(arg);
532 continue;
533 }
534 // list(…) of named function arguments (R5/R6 methods).
535 if v.kind() == "call" && self.callee_name(v) == Some("list") {
536 if let Some(list_args) = v.child_by_field_name("arguments") {
537 let mut lc = list_args.walk();
538 let entries: Vec<Node<'t>> = list_args.named_children(&mut lc).collect();
539 for entry in entries {
540 if entry.kind() == "argument" {
541 self.emit_method_arg(entry);
542 }
543 }

Callers 1

hook_callMethod · 0.80

Calls 8

walkMethod · 0.80
literal_or_identifierMethod · 0.80
emit_method_argMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
collectMethod · 0.45
push_ref_atMethod · 0.45
callee_nameMethod · 0.45

Tested by

no test coverage detected