aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2')
-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}