Skip to main content

lex_vcs/
diff_report.rs

1//! Plain-data shape of the `lex ast-diff` output. Lives in lex-vcs
2//! so both the CLI (which produces it) and `diff_to_ops` (which
3//! consumes it) can share types without a cyclic dep.
4
5use serde::Serialize;
6
7#[derive(Debug, Clone, Serialize)]
8pub struct AddRemove {
9    pub name: String,
10    pub signature: String,
11    /// The SigId of the *old* side, resolved directly by whoever built
12    /// this report (`compute_diff`, or a hand-assembled report) instead
13    /// of being re-derived later from a bare-name lookup — see #818.
14    /// `None` for an `added` entry (nothing old to resolve); always
15    /// `Some` for a `removed` entry.
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub old_sig_id: Option<String>,
18}
19
20#[derive(Debug, Clone, Serialize)]
21pub struct Renamed {
22    pub from: String,
23    pub to: String,
24    pub signature: String,
25    /// The SigId of the `from` side. See `AddRemove::old_sig_id` — same
26    /// rationale, always required here since a rename always has an old
27    /// side.
28    pub old_sig_id: String,
29}
30
31#[derive(Debug, Clone, Serialize)]
32pub struct Modified {
33    pub name: String,
34    pub signature_before: String,
35    pub signature_after: String,
36    pub signature_changed: bool,
37    pub effect_changes: EffectChanges,
38    pub body_patches: Vec<BodyPatch>,
39    /// The SigId of the pre-modification side. See
40    /// `AddRemove::old_sig_id` — same rationale.
41    pub old_sig_id: String,
42}
43
44#[derive(Debug, Clone, Serialize, Default)]
45pub struct EffectChanges {
46    pub before: Vec<String>,
47    pub after: Vec<String>,
48    pub added: Vec<String>,
49    pub removed: Vec<String>,
50}
51
52#[derive(Debug, Clone, Serialize)]
53pub struct BodyPatch {
54    pub op: String,
55    pub node_path: String,
56    pub from_kind: String,
57    pub to_kind: String,
58}
59
60#[derive(Debug, Clone, Serialize, Default)]
61pub struct DiffReport {
62    pub added: Vec<AddRemove>,
63    pub removed: Vec<AddRemove>,
64    pub renamed: Vec<Renamed>,
65    pub modified: Vec<Modified>,
66}