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

Method extract_fn_or_method

codegraph-kernel/src/rustlang.rs:543–628  ·  view source on GitHub ↗

extractFunction/extractMethod, decision resolved once: method iff a receiver is found (fn inside an impl — including a NESTED fn inside an impl method's body, whose parent walk passes through the outer fn) or the stack top is class-like (trait members).

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

Source from the content-addressed store, hash-verified

541 /// impl method's body, whose parent walk passes through the outer fn) or
542 /// the stack top is class-like (trait members).
543 fn extract_fn_or_method(&mut self, node: Node<'t>) {
544 stack_guard!();
545 let receiver = self.receiver_type_of(node);
546 let as_method = receiver.is_some() || self.inside_class_like();
547
548 let name = self.extract_name(node);
549 if name == "<anonymous>" {
550 if let Some(body) = node.child_by_field_name("body") {
551 self.visit_function_body(body);
552 }
553 return;
554 }
555
556 // Match the wasm walker's sibling-attribute handling for Tauri commands.
557 let mut decorators = None;
558 if node.kind() == "function_item" {
559 let mut sibling = node.prev_named_sibling();
560 while let Some(item) = sibling {
561 match item.kind() {
562 "line_comment" | "block_comment" => {},
563 "attribute_item" => {
564 let name = item.named_child(0).and_then(|a| a.named_child(0));
565 if let Some(name) = name {
566 let text: String = self.src[name.byte_range()].chars()
567 .filter(|c| !c.is_whitespace()).collect();
568 if text == "tauri::command" {
569 decorators = Some("tauri::command".to_string());
570 break;
571 }
572 }
573 },
574 _ => break,
575 }
576 sibling = item.prev_named_sibling();
577 }
578 }
579 let extra = Extra {
580 decorators,
581 docstring: preceding_docstring(node, self.src),
582 signature: self.signature_of(node),
583 visibility: Some(self.visibility_of(node)),
584 // isAsync hook exists but never finds a direct `async` child (it
585 // nests in function_modifiers) — present-false on every node.
586 is_async: Some(false),
587 return_type: self.return_type_of(node),
588 qualified_name: receiver.as_ref().map(|r| format!("{r}::{name}")),
589 ..Extra::default() // isExported hook absent → flag not set
590 };
591 let kind: &'static str = if as_method { "method" } else { "function" };
592 let Some(row) = self.create_node(kind, &name, node, extra) else { return };
593
594 // Contains edge from the owner: receiver present AND not class-like —
595 // FIRST earlier-in-file struct/class/enum/trait of the receiver's name.
596 if as_method && !self.inside_class_like() {
597 if let Some(receiver) = &receiver {
598 let owner_row = self
599 .nodes_meta
600 .iter()

Callers 2

visit_nodeMethod · 0.80

Calls 15

preceding_docstringFunction · 0.85
edge_kind_indexFunction · 0.85
mapMethod · 0.80
positionMethod · 0.80
push_edgeMethod · 0.80
pushMethod · 0.80
unwrapMethod · 0.60
receiver_type_ofMethod · 0.45
inside_class_likeMethod · 0.45
extract_nameMethod · 0.45
visit_function_bodyMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected