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

Method extract_method

codegraph-kernel/src/go.rs:515–565  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

513 }
514
515 fn extract_method(&mut self, node: Node<'t>) {
516 // methodsAreTopLevel: always a method. Receiver-qualified name +
517 // a contains edge from the FIRST earlier struct/class/enum/trait
518 // node of the receiver's name (mirrors the this.nodes.find scan).
519 let receiver_type = self.receiver_type_of(node);
520 let name = self.extract_name(node);
521 let extra = Extra {
522 docstring: self.docstring_of(node),
523 signature: self.signature_of(node),
524 return_type: self.return_type_of(node),
525 qualified_name: receiver_type.as_ref().map(|r| format!("{r}::{name}")),
526 // methodsAreTopLevel: a Go method is a top-level declaration, so
527 // extractMethod gives it the function's exportedness (name case).
528 is_exported: Some(self.is_exported(node)),
529 ..Extra::default()
530 };
531 let Some(row) = self.create_node("method", &name, node, extra) else { return };
532
533 if let Some(receiver_type) = &receiver_type {
534 if !self.inside_class_like() {
535 let owner_row = self
536 .nodes_meta
537 .iter()
538 .position(|m| {
539 m.name == *receiver_type
540 && matches!(m.kind, "struct" | "class" | "enum" | "trait")
541 })
542 .map(|i| i as u32);
543 if let Some(owner_row) = owner_row {
544 self.tables.push_edge(&EdgeRow {
545 source_idx: owner_row,
546 target_idx: row,
547 kind: edge_kind_index("contains").unwrap(),
548 provenance: 0,
549 line: NONE,
550 column: NONE,
551 metadata_json: NONE_STR,
552 source_id_str: NONE_STR,
553 target_id_str: NONE_STR,
554 });
555 }
556 }
557 }
558
559 self.extract_type_annotations(node, row);
560 self.stack.push(Scope { row, kind: "method", name });
561 if let Some(body) = node.child_by_field_name("body") {
562 self.visit_function_body(body);
563 }
564 self.stack.pop();
565 }
566
567 /// extractTypeAlias for Go: type_spec (`type A B`) and type_alias
568 /// (`type A = B`) → struct / interface / plain alias.

Callers 1

visit_nodeMethod · 0.45

Calls 15

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
extract_nameMethod · 0.45
docstring_ofMethod · 0.45
signature_ofMethod · 0.45
return_type_ofMethod · 0.45
is_exportedMethod · 0.45

Tested by

no test coverage detected