code_moniker_workspace/changes/semantic/
model.rs1use std::path::PathBuf;
2
3use code_moniker_core::core::moniker::Moniker;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub enum SemanticKind {
7 Added,
8 Removed,
9 BodyModified,
10 SignatureChanged,
11 Renamed,
12 Moved,
13 AttributeChanged,
14}
15
16impl SemanticKind {
17 pub fn label(self) -> &'static str {
18 match self {
19 Self::Added => "added",
20 Self::Removed => "removed",
21 Self::BodyModified => "body-modified",
22 Self::SignatureChanged => "signature-changed",
23 Self::Renamed => "renamed",
24 Self::Moved => "moved",
25 Self::AttributeChanged => "attribute-changed",
26 }
27 }
28}
29
30#[derive(Clone, Copy, Debug, Eq, PartialEq)]
31pub enum Confidence {
32 Certain,
33 Candidate,
34}
35
36impl Confidence {
37 pub fn label(self) -> &'static str {
38 match self {
39 Self::Certain => "certain",
40 Self::Candidate => "candidate",
41 }
42 }
43}
44
45#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
46pub struct ChangeFacets {
47 pub body_changed: bool,
48 pub signature_changed: bool,
49 pub visibility_changed: bool,
50 pub header_changed: bool,
51 pub file_moved: bool,
52}
53
54impl ChangeFacets {
55 pub fn any(self) -> bool {
56 self.body_changed
57 || self.signature_changed
58 || self.visibility_changed
59 || self.header_changed
60 || self.file_moved
61 }
62}
63
64#[derive(Clone, Debug, Eq, PartialEq)]
65pub struct SymbolSide {
66 pub moniker: Moniker,
67 pub file_path: PathBuf,
68 pub kind: String,
69 pub name: String,
70 pub visibility: String,
71 pub signature: String,
72 pub line_range: Option<(u32, u32)>,
73 pub body_hash: u64,
74}
75
76#[derive(Clone, Debug, Eq, PartialEq)]
77pub struct SymbolChange {
78 pub kind: SemanticKind,
79 pub confidence: Confidence,
80 pub facets: ChangeFacets,
81 pub old: Option<SymbolSide>,
82 pub new: Option<SymbolSide>,
83}
84
85#[derive(Clone, Copy, Debug, Eq, PartialEq)]
86pub enum RefChangeKind {
87 ImportRetargeted,
88 CallSiteRetargeted,
89 Added,
90 Removed,
91}
92
93impl RefChangeKind {
94 pub fn label(self) -> &'static str {
95 match self {
96 Self::ImportRetargeted => "import-retargeted",
97 Self::CallSiteRetargeted => "call-site-retargeted",
98 Self::Added => "ref-added",
99 Self::Removed => "ref-removed",
100 }
101 }
102
103 pub fn is_retarget(self) -> bool {
104 matches!(self, Self::ImportRetargeted | Self::CallSiteRetargeted)
105 }
106}
107
108#[derive(Clone, Debug, Eq, PartialEq)]
109pub struct RefChange {
110 pub kind: RefChangeKind,
111 pub file_path: PathBuf,
112 pub ref_kind: String,
113 pub old_target: Option<Moniker>,
114 pub new_target: Option<Moniker>,
115 pub old_line_range: Option<(u32, u32)>,
116 pub new_line_range: Option<(u32, u32)>,
117}
118
119#[derive(Clone, Debug, Default, Eq, PartialEq)]
120pub struct HunkCoverage {
121 pub old_residual: Vec<(u32, u32)>,
122 pub new_residual: Vec<(u32, u32)>,
123}
124
125impl HunkCoverage {
126 pub fn explained(&self) -> bool {
127 self.old_residual.is_empty() && self.new_residual.is_empty()
128 }
129}