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

Method extract_class_members

codegraph-kernel/src/rlang.rs:484–546  ·  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

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

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