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

Method extract_import

codegraph-kernel/src/dart.rs:1134–1180  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1132 // --- extractImport (:3170; hook dart.ts extractImport) -----------------
1133
1134 fn extract_import(&mut self, node: Node<'t>) {
1135 let find_child = |parent: Node<'t>, kind: &str| -> Option<Node<'t>> {
1136 let mut cursor = parent.walk();
1137 let found = parent.named_children(&mut cursor).find(|c| c.kind() == kind);
1138 found
1139 };
1140 let uri_of = |spec: Node<'t>| -> Option<Node<'t>> {
1141 let configurable = find_child(spec, "configurable_uri")?;
1142 let uri = find_child(configurable, "uri")?;
1143 find_child(uri, "string_literal")
1144 };
1145 let mut module: Option<String> = None;
1146 // A part: `part 'x.g.dart';` holds its `uri` directly.
1147 if node.kind() == "part_directive" {
1148 if let Some(sl) = find_child(node, "uri").and_then(|uri| find_child(uri, "string_literal")) {
1149 module = Some(self.text(sl).replace(['\'', '"'], ""));
1150 }
1151 }
1152 if let Some(li) = find_child(node, "library_import") {
1153 if let Some(spec) = find_child(li, "import_specification") {
1154 if let Some(sl) = uri_of(spec) {
1155 module = Some(self.text(sl).replace(['\'', '"'], ""));
1156 }
1157 }
1158 }
1159 if module.is_none() {
1160 if let Some(le) = find_child(node, "library_export") {
1161 if let Some(sl) = uri_of(le) {
1162 module = Some(self.text(sl).replace(['\'', '"'], ""));
1163 }
1164 }
1165 }
1166 // Deferred imports (bare `uri`, no configurable_uri) → hook null →
1167 // nothing at all (invisible).
1168 let Some(module) = module.filter(|m| !m.is_empty()) else { return };
1169 let signature = self.text(node).trim().to_string();
1170 let created = self.create_node(
1171 "import",
1172 &module,
1173 node,
1174 Extra { signature: Some(signature), ..Default::default() },
1175 );
1176 if created.is_some() && !self.stack.is_empty() {
1177 let parent_row = self.top_row();
1178 self.push_ref_at(parent_row, &module, "imports", node);
1179 }
1180 }
1181
1182 // --- extractInstantiation (:4610, generic tail) -----------------------
1183

Callers 1

visitMethod · 0.45

Calls 5

walkMethod · 0.80
textMethod · 0.65
create_nodeMethod · 0.45
top_rowMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected