aft_parse/callgraph_extractor.rs
1//! What the call-graph extractor reads and which version of it wrote a
2//! stored extraction: the source files it parses, the resolver
3//! configuration files it reads raw, and its version string.
4
5use std::path::Path;
6
7/// Bump when extracted evidence, its encoding or interpretation changes. Version
8/// 9 omits the extraction-only AST index from stored payloads; facts are unchanged.
9/// Version 10 stores the parser's corrected symbols: Go type aliases, separate
10/// ranges for specs in a grouped `type (...)` block, and non-inverted ranges for
11/// HTML headings that share a row.
12/// Version 14 records the facts behind precise Go receiver, Python package and
13/// `super()`, TypeScript object-member and Rust trait and associated calls.
14pub const PRODUCER: &str = "ruled-callgraph-v14-resolver-precision";
15
16/// The language the call graph parses the source file at `path` as, or `None`
17/// for a file it does not parse. Markdown has outline headings, not callable
18/// definitions or call references, so it is never parsed.
19pub fn source_language(path: &Path) -> Option<crate::parser::LangId> {
20 crate::parser::detect_language(path)
21 .filter(|language| *language != crate::parser::LangId::Markdown)
22}
23
24/// Whether the file at root-relative `path` (with `/` separators) is resolver
25/// configuration, such as `package.json` or `Cargo.toml`, that the call graph
26/// reads raw instead of parsing as source.
27pub fn is_resolution_input(path: &[u8]) -> bool {
28 let name = path.rsplit(|byte| *byte == b'/').next().unwrap_or(path);
29 name == b"package.json"
30 || name == b"pnpm-workspace.yaml"
31 || name == b"Cargo.toml"
32 || name == b"go.mod"
33 || name == b".gitignore"
34 || cfg!(feature = "wasm-grammars") && name == b".luaurc"
35 || name.starts_with(b"tsconfig") && name.ends_with(b".json")
36}