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

Method extract_instantiation

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

901 /// semantics: slice(lastDot+1) after a `::` leaves one `:`, then ONE
902 /// leading `[:.]` is stripped).
903 fn extract_instantiation(&mut self, node: Node<'t>) {
904 if self.stack.is_empty() {
905 return;
906 }
907 let ctor = node
908 .child_by_field_name("constructor")
909 .or_else(|| node.child_by_field_name("type"))
910 .or_else(|| node.child_by_field_name("name"))
911 .or_else(|| node.named_child(0));
912 let Some(ctor) = ctor else { return };
913
914 let mut class_name = self.text(ctor).to_string();
915 if let Some(lt) = class_name.find('<') {
916 if lt > 0 {
917 class_name.truncate(lt);
918 }
919 }
920 let last_dot = class_name.rfind('.').map(|i| i as i64).unwrap_or(-1);
921 let last_colon = class_name.rfind("::").map(|i| i as i64).unwrap_or(-1);
922 let last = last_dot.max(last_colon);
923 if last >= 0 {
924 class_name = class_name[(last + 1) as usize..].to_string();
925 if let Some(rest) = class_name.strip_prefix(&[':', '.'][..]) {
926 class_name = rest.to_string();
927 }
928 }
929 let class_name = class_name.trim().to_string();
930
931 if !class_name.is_empty() {
932 let from = self.top_row();
933 self.push_ref_at(from, &class_name, edge_kind_index("instantiates").unwrap(), node);
934 }
935 }
936
937 /// extractRustRouteMacro — body-walker-only; bare `routes`/`catchers`
938 /// identifiers only (`rocket::routes![…]` is skipped); identifier runs in

Callers 2

visit_nodeMethod · 0.45

Calls 5

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

Tested by

no test coverage detected