mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 05:08:52 +00:00
Provide better stack trace for overlapping edits
Overlapping indels are a bug. Checking this *always* is tricky (needs a sorted data structure to not suffer O(N^2) perf). But opportunistically checking small indels should give provide 80% of the benefits.
This commit is contained in:
parent
7fcda5aa46
commit
7239d8ca95
1 changed files with 9 additions and 3 deletions
|
@ -159,13 +159,13 @@ impl<'a> IntoIterator for &'a TextEdit {
|
||||||
|
|
||||||
impl TextEditBuilder {
|
impl TextEditBuilder {
|
||||||
pub fn replace(&mut self, range: TextRange, replace_with: String) {
|
pub fn replace(&mut self, range: TextRange, replace_with: String) {
|
||||||
self.indels.push(Indel::replace(range, replace_with))
|
self.indel(Indel::replace(range, replace_with))
|
||||||
}
|
}
|
||||||
pub fn delete(&mut self, range: TextRange) {
|
pub fn delete(&mut self, range: TextRange) {
|
||||||
self.indels.push(Indel::delete(range))
|
self.indel(Indel::delete(range))
|
||||||
}
|
}
|
||||||
pub fn insert(&mut self, offset: TextSize, text: String) {
|
pub fn insert(&mut self, offset: TextSize, text: String) {
|
||||||
self.indels.push(Indel::insert(offset, text))
|
self.indel(Indel::insert(offset, text))
|
||||||
}
|
}
|
||||||
pub fn finish(self) -> TextEdit {
|
pub fn finish(self) -> TextEdit {
|
||||||
let mut indels = self.indels;
|
let mut indels = self.indels;
|
||||||
|
@ -175,6 +175,12 @@ impl TextEditBuilder {
|
||||||
pub fn invalidates_offset(&self, offset: TextSize) -> bool {
|
pub fn invalidates_offset(&self, offset: TextSize) -> bool {
|
||||||
self.indels.iter().any(|indel| indel.delete.contains_inclusive(offset))
|
self.indels.iter().any(|indel| indel.delete.contains_inclusive(offset))
|
||||||
}
|
}
|
||||||
|
fn indel(&mut self, indel: Indel) {
|
||||||
|
self.indels.push(indel);
|
||||||
|
if self.indels.len() <= 16 {
|
||||||
|
check_disjoint(&mut self.indels);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {
|
fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue