diff options
author | Bernardo <[email protected]> | 2018-12-11 18:07:17 +0000 |
---|---|---|
committer | Bernardo <[email protected]> | 2018-12-11 18:07:17 +0000 |
commit | 0527e3b283af0153cf13fa64fe73862a5b7655c8 (patch) | |
tree | 07c4eacaad717ea802ab26972f45223281f2c9c1 /crates/ra_text_edit | |
parent | 7344d28768c43d8955bf23c183d606be08f27c64 (diff) |
rename Edit to TextEdit and AtomEdit to AtomTextEdit
Diffstat (limited to 'crates/ra_text_edit')
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 20 | ||||
-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 @@ | |||
1 | mod edit; | 1 | mod text_edit; |
2 | pub mod text_utils; | 2 | pub mod text_utils; |
3 | 3 | ||
4 | pub use crate::edit::{Edit, EditBuilder}; | 4 | pub use crate::text_edit::{TextEdit, TextEditBuilder}; |
5 | 5 | ||
6 | use text_unit::{TextRange, TextUnit}; | 6 | use text_unit::{TextRange, TextUnit}; |
7 | 7 | ||
8 | #[derive(Debug, Clone)] | 8 | #[derive(Debug, Clone)] |
9 | pub struct AtomEdit { | 9 | pub struct AtomTextEdit { |
10 | pub delete: TextRange, | 10 | pub delete: TextRange, |
11 | pub insert: String, | 11 | pub insert: String, |
12 | } | 12 | } |
13 | 13 | ||
14 | impl AtomEdit { | 14 | impl 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 @@ | |||
1 | use crate::AtomEdit; | 1 | use crate::AtomTextEdit; |
2 | use crate::text_utils::contains_offset_nonstrict; | 2 | use crate::text_utils::contains_offset_nonstrict; |
3 | use text_unit::{TextRange, TextUnit}; | 3 | use text_unit::{TextRange, TextUnit}; |
4 | 4 | ||
5 | #[derive(Debug, Clone)] | 5 | #[derive(Debug, Clone)] |
6 | pub struct Edit { | 6 | pub struct TextEdit { |
7 | atoms: Vec<AtomEdit>, | 7 | atoms: Vec<AtomTextEdit>, |
8 | } | 8 | } |
9 | 9 | ||
10 | #[derive(Debug)] | 10 | #[derive(Debug)] |
11 | pub struct EditBuilder { | 11 | pub struct TextEditBuilder { |
12 | atoms: Vec<AtomEdit>, | 12 | atoms: Vec<AtomTextEdit>, |
13 | } | 13 | } |
14 | 14 | ||
15 | impl EditBuilder { | 15 | impl 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 | ||
43 | impl Edit { | 43 | impl 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 | ||