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

Method extract_fn_or_method

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

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