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

Method extract_instantiation

codegraph-kernel/src/rustlang.rs:869–901  ·  view source on GitHub ↗

extractInstantiation — struct_expression via the GENERIC path: strip from the first `<`, keep the trailing `::`/`.` segment (JS slice semantics: slice(lastDot+1) after a `::` leaves one `:`, then ONE leading `[:.]` is stripped).

(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

867 /// semantics: slice(lastDot+1) after a `::` leaves one `:`, then ONE
868 /// leading `[:.]` is stripped).
869 fn extract_instantiation(&mut self, node: Node<'t>) {
870 if self.stack.is_empty() {
871 return;
872 }
873 let ctor = node
874 .child_by_field_name("constructor")
875 .or_else(|| node.child_by_field_name("type"))
876 .or_else(|| node.child_by_field_name("name"))
877 .or_else(|| node.named_child(0));
878 let Some(ctor) = ctor else { return };
879
880 let mut class_name = self.text(ctor).to_string();
881 if let Some(lt) = class_name.find('<') {
882 if lt > 0 {
883 class_name.truncate(lt);
884 }
885 }
886 let last_dot = class_name.rfind('.').map(|i| i as i64).unwrap_or(-1);
887 let last_colon = class_name.rfind("::").map(|i| i as i64).unwrap_or(-1);
888 let last = last_dot.max(last_colon);
889 if last >= 0 {
890 class_name = class_name[(last + 1) as usize..].to_string();
891 if let Some(rest) = class_name.strip_prefix(&[':', '.'][..]) {
892 class_name = rest.to_string();
893 }
894 }
895 let class_name = class_name.trim().to_string();
896
897 if !class_name.is_empty() {
898 let from = self.top_row();
899 self.push_ref_at(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
900 }
901 }
902
903 /// extractRustRouteMacro — body-walker-only; bare `routes`/`catchers`
904 /// identifiers only (`rocket::routes![…]` is skipped); identifier runs in

Callers 2

visit_nodeMethod · 0.45

Calls 5

edge_kind_indexFunction · 0.85
unwrapMethod · 0.60
textMethod · 0.45
top_rowMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected