MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / extract_use

Method extract_use

atomic-semantic/src/parsers/rust.rs:363–382  ·  view source on GitHub ↗

Extract a use declaration.

(&self, node: &Node, source: &str, file_path: &str)

Source from the content-addressed store, hash-verified

361
362 /// Extract a use declaration.
363 fn extract_use(&self, node: &Node, source: &str, file_path: &str) -> Option<Entity> {
364 let line = node.start_position().row as u32 + 1;
365 let end_line = node.end_position().row as u32 + 1;
366
367 let text = self.node_text(node, source);
368
369 // Extract the path from `use std::io::Read;`
370 let name = text
371 .strip_prefix("pub ")
372 .unwrap_or(&text)
373 .strip_prefix("use ")
374 .unwrap_or(&text)
375 .trim_end_matches(';')
376 .to_string();
377
378 let mut entity = Entity::new(name, EntityKind::Import, file_path, line, end_line);
379 entity = entity.with_signature(text);
380
381 Some(entity)
382 }
383
384 // ── Signature builders ──────────────────────────────────────────
385

Callers 1

walk_treeMethod · 0.80

Calls 2

with_signatureMethod · 0.80
node_textMethod · 0.45

Tested by

no test coverage detected