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

Method extract_instantiation

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

Source from the content-addressed store, hash-verified

2398 }
2399
2400 pub(super) fn extract_instantiation(&mut self, node: Node<'t>) {
2401 if self.stack.is_empty() {
2402 return;
2403 }
2404 let ctor = node
2405 .child_by_field_name("constructor")
2406 .or_else(|| node.child_by_field_name("type"))
2407 .or_else(|| node.child_by_field_name("name"))
2408 .or_else(|| node.named_child(0));
2409 let Some(ctor) = ctor else { return };
2410
2411 let mut class_name = self.text(ctor).to_string();
2412 // `new Map<K, V>()` → Map.
2413 if let Some(lt) = class_name.find('<') {
2414 if lt > 0 {
2415 class_name.truncate(lt);
2416 }
2417 }
2418 // `new ns.Foo()` → Foo.
2419 let last_dot = class_name
2420 .rfind('.')
2421 .map(|i| i as isize)
2422 .unwrap_or(-1)
2423 .max(class_name.rfind("::").map(|i| i as isize).unwrap_or(-1));
2424 if last_dot >= 0 {
2425 class_name = class_name[(last_dot as usize + 1)..].to_string();
2426 // TS: .replace(/^[:.]/, '') — one leading colon-or-dot.
2427 if class_name.starts_with(':') || class_name.starts_with('.') {
2428 class_name.remove(0);
2429 }
2430 }
2431 let class_name = class_name.trim().to_string();
2432 if !class_name.is_empty() {
2433 let from = self.top_row();
2434 self.push_ref(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
2435 }
2436 }
2437
2438 // --- extractDecoratorsFor --------------------------------------------------------------
2439

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_refMethod · 0.45

Tested by

no test coverage detected