aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-25 10:44:26 +0100
committerAleksey Kladov <[email protected]>2018-08-25 10:44:26 +0100
commit32c8ea93074286f3111317fe3077698c0afe929f (patch)
treee388b0fad293968c1b5ef0163de7a81408ad1367 /crates/libsyntax2/src
parent87cd57d56aeafa1117a6163249d210f39efe8f28 (diff)
Move atom edit to libsyntax2
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/lib.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs
index 01e155855..86fdbd23f 100644
--- a/crates/libsyntax2/src/lib.rs
+++ b/crates/libsyntax2/src/lib.rs
@@ -64,7 +64,7 @@ impl File {
64 validate_block_structure(root.borrowed()); 64 validate_block_structure(root.borrowed());
65 File { root } 65 File { root }
66 } 66 }
67 pub fn parse(text: &str) -> Self { 67 pub fn parse(text: &str) -> File {
68 let tokens = tokenize(&text); 68 let tokens = tokenize(&text);
69 let (root, errors) = parser_impl::parse::<yellow::GreenBuilder>(text, &tokens); 69 let (root, errors) = parser_impl::parse::<yellow::GreenBuilder>(text, &tokens);
70 File::new(root, errors) 70 File::new(root, errors)
@@ -112,3 +112,23 @@ fn validate_block_structure(root: SyntaxNodeRef) {
112 } 112 }
113 } 113 }
114} 114}
115
116#[derive(Debug, Clone)]
117pub struct AtomEdit {
118 pub delete: TextRange,
119 pub insert: String,
120}
121
122impl AtomEdit {
123 pub fn replace(range: TextRange, replace_with: String) -> AtomEdit {
124 AtomEdit { delete: range, insert: replace_with }
125 }
126
127 pub fn delete(range: TextRange) -> AtomEdit {
128 AtomEdit::replace(range, String::new())
129 }
130
131 pub fn insert(offset: TextUnit, text: String) -> AtomEdit {
132 AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text)
133 }
134}