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.rs20
-rw-r--r--crates/ra_text_edit/src/text_edit.rs (renamed from crates/ra_text_edit/src/edit.rs)30
2 files changed, 25 insertions, 25 deletions
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs
index 789471e8a..13e20f6fb 100644
--- a/crates/ra_text_edit/src/lib.rs
+++ b/crates/ra_text_edit/src/lib.rs
@@ -1,29 +1,29 @@
1mod edit; 1mod text_edit;
2pub mod text_utils; 2pub mod text_utils;
3 3
4pub use crate::edit::{Edit, EditBuilder}; 4pub use crate::text_edit::{TextEdit, TextEditBuilder};
5 5
6use text_unit::{TextRange, TextUnit}; 6use text_unit::{TextRange, TextUnit};
7 7
8#[derive(Debug, Clone)] 8#[derive(Debug, Clone)]
9pub struct AtomEdit { 9pub struct AtomTextEdit {
10 pub delete: TextRange, 10 pub delete: TextRange,
11 pub insert: String, 11 pub insert: String,
12} 12}
13 13
14impl AtomEdit { 14impl AtomTextEdit {
15 pub fn replace(range: TextRange, replace_with: String) -> AtomEdit { 15 pub fn replace(range: TextRange, replace_with: String) -> AtomTextEdit {
16 AtomEdit { 16 AtomTextEdit {
17 delete: range, 17 delete: range,
18 insert: replace_with, 18 insert: replace_with,
19 } 19 }
20 } 20 }
21 21
22 pub fn delete(range: TextRange) -> AtomEdit { 22 pub fn delete(range: TextRange) -> AtomTextEdit {
23 AtomEdit::replace(range, String::new()) 23 AtomTextEdit::replace(range, String::new())
24 } 24 }
25 25
26 pub fn insert(offset: TextUnit, text: String) -> AtomEdit { 26 pub fn insert(offset: TextUnit, text: String) -> AtomTextEdit {
27 AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text) 27 AtomTextEdit::replace(TextRange::offset_len(offset, 0.into()), text)
28 } 28 }
29} 29}
diff --git a/crates/ra_text_edit/src/edit.rs b/crates/ra_text_edit/src/text_edit.rs
index 560cf2bbc..fb46f046d 100644
--- a/crates/ra_text_edit/src/edit.rs
+++ b/crates/ra_text_edit/src/text_edit.rs
@@ -1,37 +1,37 @@
1use crate::AtomEdit; 1use crate::AtomTextEdit;
2use crate::text_utils::contains_offset_nonstrict; 2use crate::text_utils::contains_offset_nonstrict;
3use text_unit::{TextRange, TextUnit}; 3use text_unit::{TextRange, TextUnit};
4 4
5#[derive(Debug, Clone)] 5#[derive(Debug, Clone)]
6pub struct Edit { 6pub struct TextEdit {
7 atoms: Vec<AtomEdit>, 7 atoms: Vec<AtomTextEdit>,
8} 8}
9 9
10#[derive(Debug)] 10#[derive(Debug)]
11pub struct EditBuilder { 11pub struct TextEditBuilder {
12 atoms: Vec<AtomEdit>, 12 atoms: Vec<AtomTextEdit>,
13} 13}
14 14
15impl EditBuilder { 15impl TextEditBuilder {
16 pub fn new() -> EditBuilder { 16 pub fn new() -> TextEditBuilder {
17 EditBuilder { atoms: Vec::new() } 17 TextEditBuilder { atoms: Vec::new() }
18 } 18 }
19 pub fn replace(&mut self, range: TextRange, replace_with: String) { 19 pub fn replace(&mut self, range: TextRange, replace_with: String) {
20 self.atoms.push(AtomEdit::replace(range, replace_with)) 20 self.atoms.push(AtomTextEdit::replace(range, replace_with))
21 } 21 }
22 pub fn delete(&mut self, range: TextRange) { 22 pub fn delete(&mut self, range: TextRange) {
23 self.atoms.push(AtomEdit::delete(range)) 23 self.atoms.push(AtomTextEdit::delete(range))
24 } 24 }
25 pub fn insert(&mut self, offset: TextUnit, text: String) { 25 pub fn insert(&mut self, offset: TextUnit, text: String) {
26 self.atoms.push(AtomEdit::insert(offset, text)) 26 self.atoms.push(AtomTextEdit::insert(offset, text))
27 } 27 }
28 pub fn finish(self) -> Edit { 28 pub fn finish(self) -> TextEdit {
29 let mut atoms = self.atoms; 29 let mut atoms = self.atoms;
30 atoms.sort_by_key(|a| (a.delete.start(), a.delete.end())); 30 atoms.sort_by_key(|a| (a.delete.start(), a.delete.end()));
31 for (a1, a2) in atoms.iter().zip(atoms.iter().skip(1)) { 31 for (a1, a2) in atoms.iter().zip(atoms.iter().skip(1)) {
32 assert!(a1.delete.end() <= a2.delete.start()) 32 assert!(a1.delete.end() <= a2.delete.start())
33 } 33 }
34 Edit { atoms } 34 TextEdit { atoms }
35 } 35 }
36 pub fn invalidates_offset(&self, offset: TextUnit) -> bool { 36 pub fn invalidates_offset(&self, offset: TextUnit) -> bool {
37 self.atoms 37 self.atoms
@@ -40,8 +40,8 @@ impl EditBuilder {
40 } 40 }
41} 41}
42 42
43impl Edit { 43impl TextEdit {
44 pub fn into_atoms(self) -> Vec<AtomEdit> { 44 pub fn into_atoms(self) -> Vec<AtomTextEdit> {
45 self.atoms 45 self.atoms
46 } 46 }
47 47