(sources: &[(String, String)])
| 60 | |
| 61 | impl SyntaxIndex { |
| 62 | pub fn from_sources(sources: &[(String, String)]) -> Self { |
| 63 | let mut parser = ParserRegistry::new(); |
| 64 | let mut index = Self::default(); |
| 65 | let mut parsed = Vec::new(); |
| 66 | let mut names = BTreeMap::<String, BTreeSet<String>>::new(); |
| 67 | for (path, source) in sources { |
| 68 | let entities = parser.extract(path, source); |
| 69 | for entity in entities.iter().filter(|entity| callable(entity)) { |
| 70 | names |
| 71 | .entry(entity.name.clone()) |
| 72 | .or_default() |
| 73 | .insert(selector(entity)); |
| 74 | } |
| 75 | index.file_modules.insert( |
| 76 | path.clone(), |
| 77 | Path::new(path) |
| 78 | .parent() |
| 79 | .and_then(|p| p.to_str()) |
| 80 | .unwrap_or_default() |
| 81 | .to_owned(), |
| 82 | ); |
| 83 | index.entities.extend(entities.clone()); |
| 84 | parsed.push((path, source, entities)); |
| 85 | } |
| 86 | for (path, source, entities) in &parsed { |
| 87 | for reference in parser.extract_references(path, source) { |
| 88 | let Some(caller) = entities |
| 89 | .iter() |
| 90 | .filter(|entity| { |
| 91 | callable(entity) |
| 92 | && reference.line >= entity.line |
| 93 | && reference.line <= entity.end_line |
| 94 | }) |
| 95 | .min_by_key(|entity| entity.end_line - entity.line) |
| 96 | else { |
| 97 | continue; |
| 98 | }; |
| 99 | let caller = selector(caller); |
| 100 | if let Some(targets) = names.get(&reference.symbol) { |
| 101 | for target in targets { |
| 102 | if target != &caller { |
| 103 | index.calls.insert((target.clone(), caller.clone())); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | for import in entities |
| 109 | .iter() |
| 110 | .filter(|entity| entity.kind == EntityKind::Import) |
| 111 | { |
| 112 | let tokens: BTreeSet<_> = import |
| 113 | .name |
| 114 | .split(|c: char| !c.is_alphanumeric() && c != '_') |
| 115 | .filter(|s| !s.is_empty()) |
| 116 | .collect(); |
| 117 | for (target, _) in sources { |
| 118 | let stem = Path::new(target) |
| 119 | .file_stem() |
nothing calls this directly
no test coverage detected