1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
use crate::graph::imports::common::extract_string_literal; use std::collections::HashSet; pub(super) fn extract(content: &str) -> HashSet<String> { let mut result = HashSet::new(); let mut in_import_block = false; for line in content.lines() { let trimmed = line.trim(); if trimmed.starts_with("//") { continue; } if trimmed == "import (" { in_import_block = true; continue; } if in_import_block { if trimmed == ")" { in_import_block = false; continue; } if let Some(path) = extract_go_import_path(trimmed) { result.insert(path.to_string()); } continue; } if let Some(rest) = trimmed.strip_prefix("import ") && let Some(path) = extract_string_literal(rest.trim()) { result.insert(path.to_string()); } } result } fn extract_go_import_path(line: &str) -> Option<&str> { let start = line.find('"')?; let rest = &line[start + 1..]; let end = rest.find('"')?; Some(&rest[..end]) }