aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_text_edit
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_text_edit')
-rw-r--r--crates/ra_text_edit/src/lib.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs
index c4f945101..199fd1096 100644
--- a/crates/ra_text_edit/src/lib.rs
+++ b/crates/ra_text_edit/src/lib.rs
@@ -3,6 +3,7 @@
3//! `rust-analyzer` never mutates text itself and only sends diffs to clients, 3//! `rust-analyzer` never mutates text itself and only sends diffs to clients,
4//! so `TextEdit` is the ultimate representation of the work done by 4//! so `TextEdit` is the ultimate representation of the work done by
5//! rust-analyzer. 5//! rust-analyzer.
6use std::{slice, vec};
6 7
7pub use text_size::{TextRange, TextSize}; 8pub use text_size::{TextRange, TextSize};
8 9
@@ -71,17 +72,24 @@ impl TextEdit {
71 TextEdit { indels } 72 TextEdit { indels }
72 } 73 }
73 74
75 pub fn len(&self) -> usize {
76 self.indels.len()
77 }
78
74 pub fn is_empty(&self) -> bool { 79 pub fn is_empty(&self) -> bool {
75 self.indels.is_empty() 80 self.indels.is_empty()
76 } 81 }
77 82
78 // FXME: impl IntoIter instead 83 pub fn iter(&self) -> slice::Iter<'_, Indel> {
79 pub fn as_indels(&self) -> &[Indel] { 84 self.indels.iter()
80 &self.indels 85 }
86
87 pub fn into_iter(self) -> vec::IntoIter<Indel> {
88 self.indels.into_iter()
81 } 89 }
82 90
83 pub fn apply(&self, text: &mut String) { 91 pub fn apply(&self, text: &mut String) {
84 match self.indels.len() { 92 match self.len() {
85 0 => return, 93 0 => return,
86 1 => { 94 1 => {
87 self.indels[0].apply(text); 95 self.indels[0].apply(text);