Skip to content

Commit 5fe5183

Browse files
committed
fix insert ranges not being excluded from disjointness
1 parent 21bb04d commit 5fe5183

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

crates/syntax/src/syntax_editor/edit_algo.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::{collections::VecDeque, ops::RangeInclusive};
22

33
use rowan::TextRange;
4-
use rustc_hash::{FxHashMap, FxHashSet};
4+
use rustc_hash::FxHashMap;
55

66
use crate::{
7-
syntax_editor::{mapping::MissingMapping, Change, ChangeKind, Position, PositionRepr},
7+
syntax_editor::{mapping::MissingMapping, Change, ChangeKind, PositionRepr},
88
SyntaxElement, SyntaxNode, SyntaxNodePtr,
99
};
1010

@@ -41,12 +41,17 @@ pub(super) fn apply_edits(editor: SyntaxEditor) -> SyntaxEdit {
4141
.then(a.change_kind().cmp(&b.change_kind()))
4242
});
4343

44-
let disjoint_replaces_ranges = changes.iter().zip(changes.iter().skip(1)).all(|(l, r)| {
45-
l.change_kind() == ChangeKind::Replace
46-
&& r.change_kind() == ChangeKind::Replace
47-
&& (l.target_parent() != r.target_parent()
44+
let disjoint_replaces_ranges = changes
45+
.iter()
46+
.zip(changes.iter().skip(1))
47+
.filter(|(l, r)| {
48+
// We only care about checking for disjoint replace ranges
49+
l.change_kind() == ChangeKind::Replace && r.change_kind() == ChangeKind::Replace
50+
})
51+
.all(|(l, r)| {
52+
(l.target_parent() != r.target_parent()
4853
|| l.target_range().intersect(r.target_range()).is_none())
49-
});
54+
});
5055

5156
if stdx::never!(
5257
!disjoint_replaces_ranges,

0 commit comments

Comments
 (0)