| 178 | } |
| 179 | |
| 180 | fn changed_entities( |
| 181 | registry: &mut ParserRegistry, |
| 182 | path: &str, |
| 183 | before: &str, |
| 184 | after: &str, |
| 185 | ) -> Option<Vec<Entity>> { |
| 186 | let definitions = |entities: Vec<Entity>| { |
| 187 | entities |
| 188 | .into_iter() |
| 189 | .filter(|entity| entity.kind != atomic_semantic::EntityKind::Import) |
| 190 | .collect::<Vec<_>>() |
| 191 | }; |
| 192 | let old = definitions(registry.extract(path, before)); |
| 193 | let new = definitions(registry.extract(path, after)); |
| 194 | if old.is_empty() && new.is_empty() { |
| 195 | return None; |
| 196 | } |
| 197 | let diff = TextDiff::configure() |
| 198 | .timeout(std::time::Duration::from_millis(100)) |
| 199 | .diff_lines(before, after); |
| 200 | let mut old_lines = BTreeSet::new(); |
| 201 | let mut new_lines = BTreeSet::new(); |
| 202 | for change in diff.iter_all_changes() { |
| 203 | match change.tag() { |
| 204 | ChangeTag::Delete => { |
| 205 | if let Some(line) = change.old_index() { |
| 206 | old_lines.insert(line as u32 + 1); |
| 207 | } |
| 208 | } |
| 209 | ChangeTag::Insert => { |
| 210 | if let Some(line) = change.new_index() { |
| 211 | new_lines.insert(line as u32 + 1); |
| 212 | } |
| 213 | } |
| 214 | _ => {} |
| 215 | } |
| 216 | } |
| 217 | let mut entities: Vec<Entity> = Vec::new(); |
| 218 | for (candidates, lines) in [(old, old_lines), (new, new_lines)] { |
| 219 | for entity in candidates { |
| 220 | if lines.range(entity.line..=entity.end_line).next().is_none() { |
| 221 | continue; |
| 222 | } |
| 223 | if let Some(existing) = entities |
| 224 | .iter_mut() |
| 225 | .find(|e| e.name == entity.name && e.kind == entity.kind) |
| 226 | { |
| 227 | // Becoming public is an API change just as becoming private is. |
| 228 | // Retain visibility from either recorded version, not whichever |
| 229 | // version happened to be visited first. |
| 230 | existing.exported |= entity.exported; |
| 231 | } else { |
| 232 | entities.push(entity); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | Some(entities) |
| 237 | } |