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

Method extract_instantiation

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

Source from the content-addressed store, hash-verified

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

Callers 2

visit_nodeMethod · 0.45

Calls 5

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

Tested by

no test coverage detected