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

Method extract_import

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

Source from the content-addressed store, hash-verified

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

Callers 1

visitMethod · 0.45

Calls 5

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

Tested by

no test coverage detected