diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/reparsing.rs | 24 | ||||
-rw-r--r-- | crates/ra_syntax/src/text_utils.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_text.rs | 3 |
4 files changed, 5 insertions, 30 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 0e5c9baad..7295fb237 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -41,13 +41,13 @@ pub use rowan::{SmolStr, TextRange, TextUnit}; | |||
41 | pub use crate::{ | 41 | pub use crate::{ |
42 | ast::AstNode, | 42 | ast::AstNode, |
43 | lexer::{tokenize, Token}, | 43 | lexer::{tokenize, Token}, |
44 | reparsing::AtomEdit, | ||
45 | syntax_kinds::SyntaxKind, | 44 | syntax_kinds::SyntaxKind, |
46 | yellow::{ | 45 | yellow::{ |
47 | Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location, | 46 | Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location, |
48 | }, | 47 | }, |
49 | }; | 48 | }; |
50 | 49 | ||
50 | use ra_text_edit::AtomEdit; | ||
51 | use crate::yellow::GreenNode; | 51 | use crate::yellow::GreenNode; |
52 | 52 | ||
53 | /// `SourceFileNode` represents a parse tree for a single Rust file. | 53 | /// `SourceFileNode` represents a parse tree for a single Rust file. |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 732fb0e4a..873809a5a 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -6,29 +6,7 @@ use crate::parser_impl; | |||
6 | use crate::text_utils::replace_range; | 6 | use crate::text_utils::replace_range; |
7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; | 7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; |
8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; | 8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; |
9 | 9 | use ra_text_edit::AtomEdit; | |
10 | #[derive(Debug, Clone)] | ||
11 | pub struct AtomEdit { | ||
12 | pub delete: TextRange, | ||
13 | pub insert: String, | ||
14 | } | ||
15 | |||
16 | impl AtomEdit { | ||
17 | pub fn replace(range: TextRange, replace_with: String) -> AtomEdit { | ||
18 | AtomEdit { | ||
19 | delete: range, | ||
20 | insert: replace_with, | ||
21 | } | ||
22 | } | ||
23 | |||
24 | pub fn delete(range: TextRange) -> AtomEdit { | ||
25 | AtomEdit::replace(range, String::new()) | ||
26 | } | ||
27 | |||
28 | pub fn insert(offset: TextUnit, text: String) -> AtomEdit { | ||
29 | AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text) | ||
30 | } | ||
31 | } | ||
32 | 10 | ||
33 | pub(crate) fn incremental_reparse( | 11 | pub(crate) fn incremental_reparse( |
34 | node: SyntaxNodeRef, | 12 | node: SyntaxNodeRef, |
diff --git a/crates/ra_syntax/src/text_utils.rs b/crates/ra_syntax/src/text_utils.rs index a90f8a083..417d43e1b 100644 --- a/crates/ra_syntax/src/text_utils.rs +++ b/crates/ra_syntax/src/text_utils.rs | |||
@@ -1,8 +1,4 @@ | |||
1 | use crate::{TextRange, TextUnit}; | 1 | use crate::TextRange; |
2 | |||
3 | pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool { | ||
4 | range.start() <= offset && offset <= range.end() | ||
5 | } | ||
6 | 2 | ||
7 | pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> { | 3 | pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> { |
8 | let start = r1.start().max(r2.start()); | 4 | let start = r1.start().max(r2.start()); |
diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs index 5395ca90b..46bde9a08 100644 --- a/crates/ra_syntax/src/yellow/syntax_text.rs +++ b/crates/ra_syntax/src/yellow/syntax_text.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use std::{fmt, ops}; | 1 | use std::{fmt, ops}; |
2 | 2 | ||
3 | use ra_text_edit::text_utils::contains_offset_nonstrict; | ||
3 | use crate::{ | 4 | use crate::{ |
4 | text_utils::{contains_offset_nonstrict, intersect}, | 5 | text_utils::intersect, |
5 | SyntaxNodeRef, TextRange, TextUnit, | 6 | SyntaxNodeRef, TextRange, TextUnit, |
6 | }; | 7 | }; |
7 | 8 | ||