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

Method extract_instantiation

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

1023 /// semantics: slice(lastDot+1) after a `::` leaves one `:`, then ONE
1024 /// leading `[:.]` is stripped).
1025 fn extract_instantiation(&mut self, node: Node<'t>) {
1026 if self.stack.is_empty() {
1027 return;
1028 }
1029 let ctor = node
1030 .child_by_field_name("constructor")
1031 .or_else(|| node.child_by_field_name("type"))
1032 .or_else(|| node.child_by_field_name("name"))
1033 .or_else(|| node.named_child(0));
1034 let Some(ctor) = ctor else { return };
1035
1036 let mut class_name = self.text(ctor).to_string();
1037 if let Some(lt) = class_name.find('<') {
1038 if lt > 0 {
1039 class_name.truncate(lt);
1040 }
1041 }
1042 let last_dot = class_name.rfind('.').map(|i| i as i64).unwrap_or(-1);
1043 let last_colon = class_name.rfind("::").map(|i| i as i64).unwrap_or(-1);
1044 let last = last_dot.max(last_colon);
1045 if last >= 0 {
1046 class_name = class_name[(last + 1) as usize..].to_string();
1047 if let Some(rest) = class_name.strip_prefix(&[':', '.'][..]) {
1048 class_name = rest.to_string();
1049 }
1050 }
1051 let class_name = class_name.trim().to_string();
1052
1053 if !class_name.is_empty() {
1054 let from = self.top_row();
1055 self.push_ref_at(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
1056 }
1057 }
1058
1059 /// extractRustMacroCalls (#3251): the calls and variant paths in the
1060 /// arguments of an expression macro (`format!`, `assert_eq!`, `vec!`,

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