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

Method extract_fn_or_method

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

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