From 32c8ea93074286f3111317fe3077698c0afe929f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Aug 2018 12:44:26 +0300 Subject: Move atom edit to libsyntax2 --- crates/libsyntax2/src/lib.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'crates/libsyntax2/src/lib.rs') 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 { validate_block_structure(root.borrowed()); File { root } } - pub fn parse(text: &str) -> Self { + pub fn parse(text: &str) -> File { let tokens = tokenize(&text); let (root, errors) = parser_impl::parse::(text, &tokens); File::new(root, errors) @@ -112,3 +112,23 @@ fn validate_block_structure(root: SyntaxNodeRef) { } } } + +#[derive(Debug, Clone)] +pub struct AtomEdit { + pub delete: TextRange, + pub insert: String, +} + +impl AtomEdit { + pub fn replace(range: TextRange, replace_with: String) -> AtomEdit { + AtomEdit { delete: range, insert: replace_with } + } + + pub fn delete(range: TextRange) -> AtomEdit { + AtomEdit::replace(range, String::new()) + } + + pub fn insert(offset: TextUnit, text: String) -> AtomEdit { + AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text) + } +} -- cgit v1.2.3