Make migration notification not display if some bug causes no changes (#24578)

When working on #24442, I did a project wide replacement of
`AcceptInlineCompletion` with `AcceptEditPrediction`, as I was updating
the branch to mmain and that rename had happened. This also replaced it
in the migrator, causing the migration notification to always pop up on
keymap changes.

Checking if the migration actually changes the text makes it behave
better if this variety of bug happens in the future.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-02-10 13:01:10 -07:00 committed by GitHub
parent 0fd2203665
commit 43afa68dab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 4 deletions

1
Cargo.lock generated
View file

@ -7878,6 +7878,7 @@ version = "0.1.0"
dependencies = [
"collections",
"convert_case 0.7.1",
"log",
"pretty_assertions",
"streaming-iterator",
"tree-sitter",

View file

@ -15,6 +15,7 @@ doctest = false
[dependencies]
collections.workspace = true
convert_case.workspace = true
log.workspace = true
streaming-iterator.workspace = true
tree-sitter-json.workspace = true
tree-sitter.workspace = true

View file

@ -29,11 +29,19 @@ fn migrate(text: &str, patterns: MigrationPatterns, query: &Query) -> Option<Str
if edits.is_empty() {
None
} else {
let mut text = text.to_string();
for (range, replacement) in edits.into_iter().rev() {
text.replace_range(range, &replacement);
let mut new_text = text.to_string();
for (range, replacement) in edits.iter().rev() {
new_text.replace_range(range.clone(), replacement);
}
if new_text == text {
log::error!(
"Edits computed for configuration migration do not cause a change: {:?}",
edits
);
None
} else {
Some(new_text)
}
Some(text)
}
}