@@ -102,6 +102,7 @@ pub(super) fn apply_edits(editor: SyntaxEditor) -> SyntaxEdit {
102
102
let mut changed_ancestors: VecDeque < ChangedAncestor > = VecDeque :: new ( ) ;
103
103
let mut dependent_changes = vec ! [ ] ;
104
104
let mut independent_changes = vec ! [ ] ;
105
+ let mut outdated_changes = vec ! [ ] ;
105
106
106
107
for ( change_index, change) in changes. iter ( ) . enumerate ( ) {
107
108
// Check if this change is dependent on another change (i.e. it's contained within another range)
@@ -116,10 +117,14 @@ pub(super) fn apply_edits(editor: SyntaxEditor) -> SyntaxEdit {
116
117
// FIXME: Resolve changes that depend on a range of elements
117
118
let ancestor = & changed_ancestors[ index] ;
118
119
119
- dependent_changes. push ( DependentChange {
120
- parent : ancestor. change_index as u32 ,
121
- child : change_index as u32 ,
122
- } ) ;
120
+ if let Change :: Replace ( _, None ) = changes[ ancestor. change_index ] {
121
+ outdated_changes. push ( change_index as u32 ) ;
122
+ } else {
123
+ dependent_changes. push ( DependentChange {
124
+ parent : ancestor. change_index as u32 ,
125
+ child : change_index as u32 ,
126
+ } ) ;
127
+ }
123
128
} else {
124
129
// This change is independent of any other change
125
130
@@ -195,8 +200,9 @@ pub(super) fn apply_edits(editor: SyntaxEditor) -> SyntaxEdit {
195
200
Change :: Replace ( target, Some ( new_target) ) => {
196
201
( to_owning_node ( target) , to_owning_node ( new_target) )
197
202
}
198
- // Silently drop outdated change
199
- Change :: Replace ( _, None ) => continue ,
203
+ Change :: Replace ( _, None ) => {
204
+ unreachable ! ( "deletions should not generate dependent changes" )
205
+ }
200
206
Change :: ReplaceAll ( _, _) | Change :: ReplaceWithMany ( _, _) => {
201
207
unimplemented ! ( "cannot resolve changes that depend on replacing many elements" )
202
208
}
@@ -234,6 +240,12 @@ pub(super) fn apply_edits(editor: SyntaxEditor) -> SyntaxEdit {
234
240
}
235
241
}
236
242
243
+ // We reverse here since we pushed to this in ascending order,
244
+ // and we want to remove elements in descending order
245
+ for idx in outdated_changes. into_iter ( ) . rev ( ) {
246
+ changes. remove ( idx as usize ) ;
247
+ }
248
+
237
249
// Apply changes
238
250
let mut root = tree_mutator. mutable_clone ;
239
251
0 commit comments