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

Method extract_instantiation

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

1025 /// semantics: slice(lastDot+1) after a `::` leaves one `:`, then ONE
1026 /// leading `[:.]` is stripped).
1027 fn extract_instantiation(&mut self, node: Node<'t>) {
1028 if self.stack.is_empty() {
1029 return;
1030 }
1031 let ctor = node
1032 .child_by_field_name("constructor")
1033 .or_else(|| node.child_by_field_name("type"))
1034 .or_else(|| node.child_by_field_name("name"))
1035 .or_else(|| node.named_child(0));
1036 let Some(ctor) = ctor else { return };
1037
1038 let mut class_name = self.text(ctor).to_string();
1039 if let Some(lt) = class_name.find('<') {
1040 if lt > 0 {
1041 class_name.truncate(lt);
1042 }
1043 }
1044 let last_dot = class_name.rfind('.').map(|i| i as i64).unwrap_or(-1);
1045 let last_colon = class_name.rfind("::").map(|i| i as i64).unwrap_or(-1);
1046 let last = last_dot.max(last_colon);
1047 if last >= 0 {
1048 class_name = class_name[(last + 1) as usize..].to_string();
1049 if let Some(rest) = class_name.strip_prefix(&[':', '.'][..]) {
1050 class_name = rest.to_string();
1051 }
1052 }
1053 let class_name = class_name.trim().to_string();
1054
1055 if !class_name.is_empty() {
1056 let from = self.top_row();
1057 self.push_ref_at(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
1058 }
1059 }
1060
1061 /// extractRustRouteMacro — body-walker-only; bare `routes`/`catchers`
1062 /// identifiers only (`rocket::routes![…]` is skipped); identifier runs in

Callers 2

visit_nodeMethod · 0.45

Calls 6

edge_kind_indexFunction · 0.85
mapMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected