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

Method extract_instantiation

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

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