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
use std::fs;
use std::process;
use crate::exit::EXIT_FAILURE;
use super::json::{extraction_to_json, ts_extraction_to_json};
use super::ts_fragment::extract_ts_file;
use super::ts_fragment_types::TsFragment;
use super::walk::extract;
// ---------------------------------------------------------------------------
// `extract-dump` subcommand -- canonical JSON for one file.
// ---------------------------------------------------------------------------
/// Extracts the C# file at `path` and prints the extraction as JSON.
pub fn run_extract_dump(path: &str) {
let source = fs::read_to_string(path).unwrap_or_else(|err| {
eprintln!("failed to read {path}: {err}");
process::exit(EXIT_FAILURE);
});
// The dump path dispatches on extension: a C# file yields a fragment read
// as `{purpose, defs, usings, refs, names}`, while a TS/JS file yields a
// `ts: 1` REFERENCE fragment carrying `defs` and `refs` but no `usings`
// and no `names` -- and serialization drops an absent value's key, so the
// TS dump is a three-key object. The C# dump below keeps all five keys.
if let Some(grammar) = crate::parse::ts_grammar_for(path) {
// Go through `extract_ts_file` -- the SAME hybrid-aware worker path
// `devscout map` uses, not the pure extractor -- so the dump shows the
// leading-comment prefix, off one single parse.
match extract_ts_file(&source, grammar) {
Some(ts) => println!("{}", ts_extraction_to_json(&ts.purpose, &ts.fragment)),
// A parse failure leaves the file out of both outputs, so its
// dump is the empty fragment under a null purpose.
None => println!("{}", ts_extraction_to_json(&None, &TsFragment::default())),
}
return;
}
let result = extract(&source);
println!("{}", extraction_to_json(&result));
}