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

Method extract_import

atomic-semantic/src/parsers/go.rs:250–273  ·  view source on GitHub ↗

Extract an import declaration.

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

Source from the content-addressed store, hash-verified

248
249 /// Extract an import declaration.
250 fn extract_import(&self, node: &Node, source: &str, file_path: &str) -> Option<Entity> {
251 let line = node.start_position().row as u32 + 1;
252 let end_line = node.end_position().row as u32 + 1;
253
254 let text = self.node_text(node, source);
255
256 // Extract the import path — for grouped imports, just use the full text
257 let name = if text.contains('(') {
258 // Grouped import: `import ( "fmt"\n "os" )`
259 "imports".to_string()
260 } else {
261 // Single import: `import "fmt"` → "fmt"
262 text.strip_prefix("import ")
263 .unwrap_or(&text)
264 .trim()
265 .trim_matches('"')
266 .to_string()
267 };
268
269 let mut entity = Entity::new(name, EntityKind::Import, file_path, line, end_line);
270 entity = entity.with_signature(text.lines().next().unwrap_or("").to_string());
271
272 Some(entity)
273 }
274
275 // ── Signature builders ──────────────────────────────────────────
276

Callers 1

walk_treeMethod · 0.45

Calls 5

with_signatureMethod · 0.80
node_textMethod · 0.45
containsMethod · 0.45
nextMethod · 0.45
linesMethod · 0.45

Tested by

no test coverage detected