Extract an import declaration.
(&self, node: &Node, source: &str, file_path: &str)
| 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 |