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

Method extract_import

atomic-semantic/src/parsers/swift.rs:329–350  ·  view source on GitHub ↗

Extract an import declaration.

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

Source from the content-addressed store, hash-verified

327
328 /// Extract an import declaration.
329 fn extract_import(&self, node: &Node, source: &str, file_path: &str) -> Option<Entity> {
330 let line = node.start_position().row as u32 + 1;
331 let end_line = node.end_position().row as u32 + 1;
332
333 let text = self.node_text(node, source);
334
335 // Try the grammar's "name" field first, fall back to text parsing
336 let name = node
337 .child_by_field_name("name")
338 .map(|n| self.node_text(&n, source))
339 .unwrap_or_else(|| {
340 text.strip_prefix("import ")
341 .unwrap_or(&text)
342 .trim()
343 .to_string()
344 });
345
346 let mut entity = Entity::new(name, EntityKind::Import, file_path, line, end_line);
347 entity = entity.with_signature(text.trim().to_string());
348
349 Some(entity)
350 }
351
352 /// Extract a typealias declaration.
353 fn extract_typealias(&self, node: &Node, source: &str, file_path: &str) -> Option<Entity> {

Callers 1

walk_treeMethod · 0.45

Calls 2

with_signatureMethod · 0.80
node_textMethod · 0.45

Tested by

no test coverage detected