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

Method extract_instantiation

codegraph-kernel/src/tsjs/extractors.rs:1103–1139  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1101 // --- extractInstantiation -----------------------------------------------------------
1102
1103 pub(super) fn extract_instantiation(&mut self, node: Node<'t>) {
1104 if self.stack.is_empty() {
1105 return;
1106 }
1107 let ctor = node
1108 .child_by_field_name("constructor")
1109 .or_else(|| node.child_by_field_name("type"))
1110 .or_else(|| node.child_by_field_name("name"))
1111 .or_else(|| node.named_child(0));
1112 let Some(ctor) = ctor else { return };
1113
1114 let mut class_name = self.text(ctor).to_string();
1115 // `new Map<K, V>()` → Map.
1116 if let Some(lt) = class_name.find('<') {
1117 if lt > 0 {
1118 class_name.truncate(lt);
1119 }
1120 }
1121 // `new ns.Foo()` → Foo.
1122 let last_dot = class_name
1123 .rfind('.')
1124 .map(|i| i as isize)
1125 .unwrap_or(-1)
1126 .max(class_name.rfind("::").map(|i| i as isize).unwrap_or(-1));
1127 if last_dot >= 0 {
1128 class_name = class_name[(last_dot as usize + 1)..].to_string();
1129 // TS: .replace(/^[:.]/, '') — one leading colon-or-dot.
1130 if class_name.starts_with(':') || class_name.starts_with('.') {
1131 class_name.remove(0);
1132 }
1133 }
1134 let class_name = class_name.trim().to_string();
1135 if !class_name.is_empty() {
1136 let from = self.top_row();
1137 self.push_ref(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
1138 }
1139 }
1140
1141 // --- extractDecoratorsFor --------------------------------------------------------------
1142

Callers 2

visit_nodeMethod · 0.45

Calls 5

edge_kind_indexFunction · 0.85
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
push_refMethod · 0.45

Tested by

no test coverage detected