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

Method extract_name_raw

codegraph-kernel/src/ccpp/mod.rs:587–631  ·  view source on GitHub ↗

extractNameRaw for the c/cpp extractor configs (nameField 'declarator'; cpp resolveName = extractCppQualifiedMethodName).

(&self, node: Node)

Source from the content-addressed store, hash-verified

585 /// extractNameRaw for the c/cpp extractor configs (nameField 'declarator';
586 /// cpp resolveName = extractCppQualifiedMethodName).
587 fn extract_name_raw(&self, node: Node) -> String {
588 if self.variant == Variant::Cpp {
589 if let Some(hook) = self.extract_cpp_qualified_method_name(node) {
590 return hook;
591 }
592 }
593 if let Some(name_node) = node.child_by_field_name("declarator") {
594 let mut resolved = name_node;
595 // Unwrap pointer/reference declarators (`int* f()`, `T& f()`).
596 while matches!(resolved.kind(), "pointer_declarator" | "reference_declarator") {
597 let inner = resolved
598 .child_by_field_name("declarator")
599 .or_else(|| resolved.named_child(0));
600 match inner {
601 Some(i) => resolved = i,
602 None => break,
603 }
604 }
605 // C++ conversion operator: `operator <type>`.
606 if resolved.kind() == "operator_cast" {
607 return match resolved.named_child(0) {
608 Some(t) => format!("operator {}", self.text(t).trim()),
609 None => self.text(resolved).to_string(),
610 };
611 }
612 if resolved.kind() == "function_declarator" || resolved.kind() == "declarator" {
613 let inner = resolved
614 .child_by_field_name("declarator")
615 .or_else(|| resolved.named_child(0));
616 return match inner {
617 Some(i) => self.text(i).to_string(),
618 None => self.text(resolved).to_string(),
619 };
620 }
621 return self.text(resolved).to_string();
622 }
623 for i in 0..node.named_child_count() {
624 if let Some(c) = node.named_child(i) {
625 if matches!(c.kind(), "identifier" | "type_identifier" | "simple_identifier" | "constant") {
626 return self.text(c).to_string();
627 }
628 }
629 }
630 "<anonymous>".to_string()
631 }
632
633 /// extractCppQualifiedMethodName (languages/c-cpp.ts:75).
634 fn extract_cpp_qualified_method_name(&self, node: Node) -> Option<String> {

Callers 1

extract_nameMethod · 0.80

Calls 2

textMethod · 0.45

Tested by

no test coverage detected