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

Method extract_fn_or_method

codegraph-kernel/src/rustlang.rs:540–625  ·  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

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