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

Method extract_method

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

Source from the content-addressed store, hash-verified

478 }
479
480 fn extract_method(&mut self, node: Node<'t>) {
481 // methodsAreTopLevel: always a method. Receiver-qualified name +
482 // a contains edge from the FIRST earlier struct/class/enum/trait
483 // node of the receiver's name (mirrors the this.nodes.find scan).
484 let receiver_type = self.receiver_type_of(node);
485 let name = self.extract_name(node);
486 let extra = Extra {
487 docstring: preceding_docstring(node, self.src),
488 signature: self.signature_of(node),
489 return_type: self.return_type_of(node),
490 qualified_name: receiver_type.as_ref().map(|r| format!("{r}::{name}")),
491 ..Extra::default() // extractMethod passes no isExported
492 };
493 let Some(row) = self.create_node("method", &name, node, extra) else { return };
494
495 if let Some(receiver_type) = &receiver_type {
496 if !self.inside_class_like() {
497 let owner_row = self
498 .nodes_meta
499 .iter()
500 .position(|m| {
501 m.name == *receiver_type
502 && matches!(m.kind, "struct" | "class" | "enum" | "trait")
503 })
504 .map(|i| i as u32);
505 if let Some(owner_row) = owner_row {
506 self.tables.push_edge(&EdgeRow {
507 source_idx: owner_row,
508 target_idx: row,
509 kind: edge_kind_index("contains").unwrap(),
510 provenance: 0,
511 line: NONE,
512 column: NONE,
513 metadata_json: NONE_STR,
514 source_id_str: NONE_STR,
515 target_id_str: NONE_STR,
516 });
517 }
518 }
519 }
520
521 self.extract_type_annotations(node, row);
522 self.stack.push(Scope { row, kind: "method", name });
523 if let Some(body) = node.child_by_field_name("body") {
524 self.visit_function_body(body);
525 }
526 self.stack.pop();
527 }
528
529 /// extractTypeAlias for Go: type_spec → struct / interface / plain alias.
530 fn extract_type_alias(&mut self, node: Node<'t>) -> bool {

Callers 1

visit_nodeMethod · 0.45

Calls 13

preceding_docstringFunction · 0.85
edge_kind_indexFunction · 0.85
positionMethod · 0.80
push_edgeMethod · 0.80
unwrapMethod · 0.60
receiver_type_ofMethod · 0.45
extract_nameMethod · 0.45
signature_ofMethod · 0.45
return_type_ofMethod · 0.45
create_nodeMethod · 0.45
inside_class_likeMethod · 0.45

Tested by

no test coverage detected