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

Method extract_import

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

Source from the content-addressed store, hash-verified

1257 // --- extractImport (:3170; hook dart.ts extractImport) -----------------
1258
1259 fn extract_import(&mut self, node: Node<'t>) {
1260 let find_child = |parent: Node<'t>, kind: &str| -> Option<Node<'t>> {
1261 let mut cursor = parent.walk();
1262 let found = parent.named_children(&mut cursor).find(|c| c.kind() == kind);
1263 found
1264 };
1265 let uri_of = |spec: Node<'t>| -> Option<Node<'t>> {
1266 let configurable = find_child(spec, "configurable_uri")?;
1267 let uri = find_child(configurable, "uri")?;
1268 find_child(uri, "string_literal")
1269 };
1270 let mut module: Option<String> = None;
1271 // A part: `part 'x.g.dart';` holds its `uri` directly.
1272 if node.kind() == "part_directive" {
1273 if let Some(sl) = find_child(node, "uri").and_then(|uri| find_child(uri, "string_literal")) {
1274 module = Some(self.text(sl).replace(['\'', '"'], ""));
1275 }
1276 }
1277 if let Some(li) = find_child(node, "library_import") {
1278 if let Some(spec) = find_child(li, "import_specification") {
1279 if let Some(sl) = uri_of(spec) {
1280 module = Some(self.text(sl).replace(['\'', '"'], ""));
1281 }
1282 }
1283 }
1284 if module.is_none() {
1285 if let Some(le) = find_child(node, "library_export") {
1286 if let Some(sl) = uri_of(le) {
1287 module = Some(self.text(sl).replace(['\'', '"'], ""));
1288 }
1289 }
1290 }
1291 // Deferred imports (bare `uri`, no configurable_uri) → hook null →
1292 // nothing at all (invisible).
1293 let Some(module) = module.filter(|m| !m.is_empty()) else { return };
1294 let signature = self.text(node).trim().to_string();
1295 let created = self.create_node(
1296 "import",
1297 &module,
1298 node,
1299 Extra { signature: Some(signature), ..Default::default() },
1300 );
1301 if created.is_some() && !self.stack.is_empty() {
1302 let parent_row = self.top_row();
1303 self.push_ref_at(parent_row, &module, "imports", node);
1304 }
1305 }
1306
1307 // --- extractInstantiation (:4610, generic tail) -----------------------
1308

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