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

Method extract_import

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

Source from the content-addressed store, hash-verified

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

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