(sources: &[(String, String)])
| 32 | |
| 33 | impl SyntaxIndex { |
| 34 | pub fn from_sources(sources: &[(String, String)]) -> Self { |
| 35 | let mut parser = ParserRegistry::new(); |
| 36 | let mut index = Self::default(); |
| 37 | let mut parsed = Vec::new(); |
| 38 | let mut paths = BTreeSet::new(); |
| 39 | for (path, source) in sources { |
| 40 | if crate::is_vault_path(path) { |
| 41 | continue; |
| 42 | } |
| 43 | paths.insert(path.clone()); |
| 44 | index.file_modules.insert( |
| 45 | path.clone(), |
| 46 | Path::new(path) |
| 47 | .parent() |
| 48 | .and_then(|p| p.to_str()) |
| 49 | .unwrap_or_default() |
| 50 | .to_owned(), |
| 51 | ); |
| 52 | match parser.analyze_source(path, source) { |
| 53 | Ok(file) => { |
| 54 | index.entities.extend(file.entities.clone()); |
| 55 | parsed.push(file); |
| 56 | } |
| 57 | Err(_) => index.entities.extend(parser.extract(path, source)), |
| 58 | } |
| 59 | } |
| 60 | let graph = SourceGraph::new(parsed, paths, true); |
| 61 | for symbol in graph |
| 62 | .symbols |
| 63 | .values() |
| 64 | .filter(|symbol| callable(&symbol.entity)) |
| 65 | { |
| 66 | for alias in [ |
| 67 | symbol.id.clone(), |
| 68 | selector(&symbol.entity), |
| 69 | symbol.entity.name.clone(), |
| 70 | ] { |
| 71 | index |
| 72 | .aliases |
| 73 | .entry(alias) |
| 74 | .or_default() |
| 75 | .insert(symbol.id.clone()); |
| 76 | } |
| 77 | } |
| 78 | for call in graph |
| 79 | .bind_calls(None) |
| 80 | .into_iter() |
| 81 | .filter(|call| call.present && call.accessible) |
| 82 | { |
| 83 | let caller = &graph.symbols[&call.call.caller]; |
| 84 | index |
| 85 | .calls |
| 86 | .insert((call.symbol.id.clone(), caller.id.clone())); |
| 87 | index |
| 88 | .bound_callers |
| 89 | .entry(call.symbol.id.clone()) |
| 90 | .or_default() |
| 91 | .push(Caller { |
nothing calls this directly
no test coverage detected