1use ryo_analysis::{SymbolId, SymbolKind, SymbolPath};
10
11#[derive(Debug, Clone)]
13pub enum MutationEvent {
14 SymbolAdded { path: SymbolPath, kind: SymbolKind },
16
17 SymbolRemoved { path: SymbolPath },
19
20 SymbolModified {
22 id: SymbolId,
23 modification: ModificationType,
24 },
25
26 SymbolRenamed {
28 old_path: SymbolPath,
29 new_path: Box<SymbolPath>,
30 },
31}
32
33#[derive(Debug, Clone)]
35pub enum ModificationType {
36 FieldAdded(String),
38 FieldRemoved(String),
40 MethodAdded(String),
42 MethodRemoved(String),
44 VariantAdded(String),
46 VariantRemoved(String),
48 VisibilityChanged,
50 DeriveAdded(String),
52 DeriveRemoved(String),
54 BodyModified,
56 TypeChanged,
58 AttributeAdded(String),
60 AttributeRemoved(String),
62 Other(String),
64}
65
66impl std::fmt::Display for MutationEvent {
67 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 match self {
69 MutationEvent::SymbolAdded { path, kind } => {
70 write!(f, "Added {:?} {}", kind, path)
71 }
72 MutationEvent::SymbolRemoved { path } => {
73 write!(f, "Removed {}", path)
74 }
75 MutationEvent::SymbolModified { id, modification } => {
76 write!(f, "Modified {:?}: {}", id, modification)
77 }
78 MutationEvent::SymbolRenamed { old_path, new_path } => {
79 write!(f, "Renamed {} -> {}", old_path, new_path)
80 }
81 }
82 }
83}
84
85impl std::fmt::Display for ModificationType {
86 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
87 match self {
88 ModificationType::FieldAdded(name) => write!(f, "field added: {}", name),
89 ModificationType::FieldRemoved(name) => write!(f, "field removed: {}", name),
90 ModificationType::MethodAdded(name) => write!(f, "method added: {}", name),
91 ModificationType::MethodRemoved(name) => write!(f, "method removed: {}", name),
92 ModificationType::VariantAdded(name) => write!(f, "variant added: {}", name),
93 ModificationType::VariantRemoved(name) => write!(f, "variant removed: {}", name),
94 ModificationType::VisibilityChanged => write!(f, "visibility changed"),
95 ModificationType::DeriveAdded(name) => write!(f, "derive added: {}", name),
96 ModificationType::DeriveRemoved(name) => write!(f, "derive removed: {}", name),
97 ModificationType::BodyModified => write!(f, "body modified"),
98 ModificationType::TypeChanged => write!(f, "type changed"),
99 ModificationType::AttributeAdded(attr) => write!(f, "attribute added: {}", attr),
100 ModificationType::AttributeRemoved(attr) => write!(f, "attribute removed: {}", attr),
101 ModificationType::Other(desc) => write!(f, "{}", desc),
102 }
103 }
104}
105
106use ryo_analysis::SymbolRegistry;
111
112pub fn collect_affected_ids(events: &[MutationEvent], registry: &SymbolRegistry) -> Vec<SymbolId> {
117 let mut ids = Vec::new();
118
119 for event in events {
120 match event {
121 MutationEvent::SymbolAdded { path, .. } => {
122 if let Some(id) = registry.lookup(path) {
124 ids.push(id);
125 }
126 }
127 MutationEvent::SymbolRemoved { path } => {
128 if let Some(id) = registry.lookup(path) {
130 ids.push(id);
131 }
132 }
133 MutationEvent::SymbolModified { id, .. } => {
134 ids.push(*id);
136 }
137 MutationEvent::SymbolRenamed { new_path, .. } => {
138 if let Some(id) = registry.lookup(new_path) {
140 ids.push(id);
141 }
142 }
143 }
144 }
145
146 ids.sort_unstable();
148 ids.dedup();
149 ids
150}