Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/text_edit.rs')
-rw-r--r--crates/ide-db/src/text_edit.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/crates/ide-db/src/text_edit.rs b/crates/ide-db/src/text_edit.rs
index 0c675f0619..b59010f2f8 100644
--- a/crates/ide-db/src/text_edit.rs
+++ b/crates/ide-db/src/text_edit.rs
@@ -8,6 +8,8 @@ use itertools::Itertools;
pub use span::{TextRange, TextSize};
use std::cmp::max;
+use crate::source_change::ChangeAnnotationId;
+
/// `InsertDelete` -- a single "atomic" change to text
///
/// Must not overlap with other `InDel`s
@@ -16,6 +18,7 @@ pub struct Indel {
pub insert: String,
/// Refers to offsets in the original text
pub delete: TextRange,
+ pub annotation: Option<ChangeAnnotationId>,
}
#[derive(Default, Debug, Clone)]
@@ -37,7 +40,7 @@ impl Indel {
Indel::replace(range, String::new())
}
pub fn replace(range: TextRange, replace_with: String) -> Indel {
- Indel { delete: range, insert: replace_with }
+ Indel { delete: range, insert: replace_with, annotation: None }
}
pub fn apply(&self, text: &mut String) {
@@ -138,6 +141,14 @@ impl TextEdit {
}
Some(res)
}
+
+ pub fn set_annotation(&mut self, annotation: Option<ChangeAnnotationId>) {
+ if annotation.is_some() {
+ for indel in &mut self.indels {
+ indel.annotation = annotation;
+ }
+ }
+ }
}
impl IntoIterator for TextEdit {
@@ -180,7 +191,7 @@ impl TextEditBuilder {
pub fn invalidates_offset(&self, offset: TextSize) -> bool {
self.indels.iter().any(|indel| indel.delete.contains_inclusive(offset))
}
- fn indel(&mut self, indel: Indel) {
+ pub fn indel(&mut self, indel: Indel) {
self.indels.push(indel);
if self.indels.len() <= 16 {
assert_disjoint_or_equal(&mut self.indels);