diff options
author | Aleksey Kladov <[email protected]> | 2019-07-20 10:58:27 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-07-20 10:58:27 +0100 |
commit | f3bdbec1b68fa0e20f0b7b6c6ef64e1507970b0d (patch) | |
tree | f2cb82f74d2d60d5351c3d7c4d8e7bce4d351cab /crates/ra_syntax | |
parent | 6d5d82e412dea19ea48eecc6f7d5a4aa223a9599 (diff) |
rename range -> text_range
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/algo.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/fuzz.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/parsing/reparsing.rs | 12 | ||||
-rw-r--r-- | crates/ra_syntax/src/ptr.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/syntax_node.rs | 14 | ||||
-rw-r--r-- | crates/ra_syntax/src/syntax_text.rs | 8 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation.rs | 8 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/block.rs | 5 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation/field_expr.rs | 2 |
10 files changed, 32 insertions, 29 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index e2de5e0e3..f47e11e66 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -25,7 +25,7 @@ pub fn ancestors_at_offset( | |||
25 | ) -> impl Iterator<Item = SyntaxNode> { | 25 | ) -> impl Iterator<Item = SyntaxNode> { |
26 | find_token_at_offset(node, offset) | 26 | find_token_at_offset(node, offset) |
27 | .map(|token| token.parent().ancestors()) | 27 | .map(|token| token.parent().ancestors()) |
28 | .kmerge_by(|node1, node2| node1.range().len() < node2.range().len()) | 28 | .kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len()) |
29 | } | 29 | } |
30 | 30 | ||
31 | /// Finds a node of specific Ast type at offset. Note that this is slightly | 31 | /// Finds a node of specific Ast type at offset. Note that this is slightly |
diff --git a/crates/ra_syntax/src/fuzz.rs b/crates/ra_syntax/src/fuzz.rs index a9146c4f8..698a624ec 100644 --- a/crates/ra_syntax/src/fuzz.rs +++ b/crates/ra_syntax/src/fuzz.rs | |||
@@ -51,7 +51,7 @@ impl CheckReparse { | |||
51 | for (a, b) in | 51 | for (a, b) in |
52 | new_parse.tree().syntax().descendants().zip(full_reparse.tree().syntax().descendants()) | 52 | new_parse.tree().syntax().descendants().zip(full_reparse.tree().syntax().descendants()) |
53 | { | 53 | { |
54 | if (a.kind(), a.range()) != (b.kind(), b.range()) { | 54 | if (a.kind(), a.text_range()) != (b.kind(), b.text_range()) { |
55 | eprint!("original:\n{:#?}", parse.tree().syntax()); | 55 | eprint!("original:\n{:#?}", parse.tree().syntax()); |
56 | eprint!("reparsed:\n{:#?}", new_parse.tree().syntax()); | 56 | eprint!("reparsed:\n{:#?}", new_parse.tree().syntax()); |
57 | eprint!("full reparse:\n{:#?}", full_reparse.tree().syntax()); | 57 | eprint!("full reparse:\n{:#?}", full_reparse.tree().syntax()); |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 605350ac4..8af04c136 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -234,7 +234,7 @@ fn api_walkthrough() { | |||
234 | assert_eq!(expr_syntax.kind(), SyntaxKind::BIN_EXPR); | 234 | assert_eq!(expr_syntax.kind(), SyntaxKind::BIN_EXPR); |
235 | 235 | ||
236 | // And text range: | 236 | // And text range: |
237 | assert_eq!(expr_syntax.range(), TextRange::from_to(32.into(), 37.into())); | 237 | assert_eq!(expr_syntax.text_range(), TextRange::from_to(32.into(), 37.into())); |
238 | 238 | ||
239 | // You can get node's text as a `SyntaxText` object, which will traverse the | 239 | // You can get node's text as a `SyntaxText` object, which will traverse the |
240 | // tree collecting token's text: | 240 | // tree collecting token's text: |
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index c7183299b..2f388bdfe 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs | |||
@@ -46,7 +46,8 @@ fn reparse_token<'node>( | |||
46 | WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { | 46 | WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { |
47 | if token.kind() == WHITESPACE || token.kind() == COMMENT { | 47 | if token.kind() == WHITESPACE || token.kind() == COMMENT { |
48 | // removing a new line may extends previous token | 48 | // removing a new line may extends previous token |
49 | if token.text().to_string()[edit.delete - token.range().start()].contains('\n') { | 49 | if token.text().to_string()[edit.delete - token.text_range().start()].contains('\n') |
50 | { | ||
50 | return None; | 51 | return None; |
51 | } | 52 | } |
52 | } | 53 | } |
@@ -62,7 +63,7 @@ fn reparse_token<'node>( | |||
62 | return None; | 63 | return None; |
63 | } | 64 | } |
64 | 65 | ||
65 | if let Some(next_char) = root.text().char_at(token.range().end()) { | 66 | if let Some(next_char) = root.text().char_at(token.text_range().end()) { |
66 | let tokens_with_next_char = tokenize(&format!("{}{}", text, next_char)); | 67 | let tokens_with_next_char = tokenize(&format!("{}{}", text, next_char)); |
67 | if tokens_with_next_char.len() == 1 { | 68 | if tokens_with_next_char.len() == 1 { |
68 | return None; | 69 | return None; |
@@ -70,7 +71,7 @@ fn reparse_token<'node>( | |||
70 | } | 71 | } |
71 | 72 | ||
72 | let new_token = GreenToken::new(rowan::SyntaxKind(token.kind().into()), text.into()); | 73 | let new_token = GreenToken::new(rowan::SyntaxKind(token.kind().into()), text.into()); |
73 | Some((token.replace_with(new_token), token.range())) | 74 | Some((token.replace_with(new_token), token.text_range())) |
74 | } | 75 | } |
75 | _ => None, | 76 | _ => None, |
76 | } | 77 | } |
@@ -90,11 +91,12 @@ fn reparse_block<'node>( | |||
90 | let mut tree_sink = TextTreeSink::new(&text, &tokens); | 91 | let mut tree_sink = TextTreeSink::new(&text, &tokens); |
91 | reparser.parse(&mut token_source, &mut tree_sink); | 92 | reparser.parse(&mut token_source, &mut tree_sink); |
92 | let (green, new_errors) = tree_sink.finish(); | 93 | let (green, new_errors) = tree_sink.finish(); |
93 | Some((node.replace_with(green), new_errors, node.range())) | 94 | Some((node.replace_with(green), new_errors, node.text_range())) |
94 | } | 95 | } |
95 | 96 | ||
96 | fn get_text_after_edit(element: SyntaxElement, edit: &AtomTextEdit) -> String { | 97 | fn get_text_after_edit(element: SyntaxElement, edit: &AtomTextEdit) -> String { |
97 | let edit = AtomTextEdit::replace(edit.delete - element.range().start(), edit.insert.clone()); | 98 | let edit = |
99 | AtomTextEdit::replace(edit.delete - element.text_range().start(), edit.insert.clone()); | ||
98 | let text = match element { | 100 | let text = match element { |
99 | SyntaxElement::Token(token) => token.text().to_string(), | 101 | SyntaxElement::Token(token) => token.text().to_string(), |
100 | SyntaxElement::Node(node) => node.text().to_string(), | 102 | SyntaxElement::Node(node) => node.text().to_string(), |
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index d1b30a2c9..8665c8976 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs | |||
@@ -12,15 +12,15 @@ pub struct SyntaxNodePtr { | |||
12 | 12 | ||
13 | impl SyntaxNodePtr { | 13 | impl SyntaxNodePtr { |
14 | pub fn new(node: &SyntaxNode) -> SyntaxNodePtr { | 14 | pub fn new(node: &SyntaxNode) -> SyntaxNodePtr { |
15 | SyntaxNodePtr { range: node.range(), kind: node.kind() } | 15 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } |
16 | } | 16 | } |
17 | 17 | ||
18 | pub fn to_node(self, root: &SyntaxNode) -> SyntaxNode { | 18 | pub fn to_node(self, root: &SyntaxNode) -> SyntaxNode { |
19 | assert!(root.parent().is_none()); | 19 | assert!(root.parent().is_none()); |
20 | successors(Some(root.clone()), |node| { | 20 | successors(Some(root.clone()), |node| { |
21 | node.children().find(|it| self.range.is_subrange(&it.range())) | 21 | node.children().find(|it| self.range.is_subrange(&it.text_range())) |
22 | }) | 22 | }) |
23 | .find(|it| it.range() == self.range && it.kind() == self.kind) | 23 | .find(|it| it.text_range() == self.range && it.kind() == self.kind) |
24 | .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) | 24 | .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) |
25 | } | 25 | } |
26 | 26 | ||
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index 3b20e96e2..c42045d77 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs | |||
@@ -53,7 +53,7 @@ impl fmt::Debug for SyntaxNode { | |||
53 | assert_eq!(level, 0); | 53 | assert_eq!(level, 0); |
54 | Ok(()) | 54 | Ok(()) |
55 | } else { | 55 | } else { |
56 | write!(f, "{:?}@{:?}", self.kind(), self.range()) | 56 | write!(f, "{:?}@{:?}", self.kind(), self.text_range()) |
57 | } | 57 | } |
58 | } | 58 | } |
59 | } | 59 | } |
@@ -80,7 +80,7 @@ impl SyntaxNode { | |||
80 | self.0.kind().0.into() | 80 | self.0.kind().0.into() |
81 | } | 81 | } |
82 | 82 | ||
83 | pub fn range(&self) -> TextRange { | 83 | pub fn text_range(&self) -> TextRange { |
84 | self.0.text_range() | 84 | self.0.text_range() |
85 | } | 85 | } |
86 | 86 | ||
@@ -291,7 +291,7 @@ pub struct SyntaxToken(pub(crate) rowan::cursor::SyntaxToken); | |||
291 | 291 | ||
292 | impl fmt::Debug for SyntaxToken { | 292 | impl fmt::Debug for SyntaxToken { |
293 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | 293 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
294 | write!(fmt, "{:?}@{:?}", self.kind(), self.range())?; | 294 | write!(fmt, "{:?}@{:?}", self.kind(), self.text_range())?; |
295 | if self.text().len() < 25 { | 295 | if self.text().len() < 25 { |
296 | return write!(fmt, " {:?}", self.text()); | 296 | return write!(fmt, " {:?}", self.text()); |
297 | } | 297 | } |
@@ -321,7 +321,7 @@ impl SyntaxToken { | |||
321 | self.0.text() | 321 | self.0.text() |
322 | } | 322 | } |
323 | 323 | ||
324 | pub fn range(&self) -> TextRange { | 324 | pub fn text_range(&self) -> TextRange { |
325 | self.0.text_range() | 325 | self.0.text_range() |
326 | } | 326 | } |
327 | 327 | ||
@@ -453,10 +453,10 @@ impl SyntaxElement { | |||
453 | .ancestors() | 453 | .ancestors() |
454 | } | 454 | } |
455 | 455 | ||
456 | pub fn range(&self) -> TextRange { | 456 | pub fn text_range(&self) -> TextRange { |
457 | match self { | 457 | match self { |
458 | SyntaxElement::Node(it) => it.range(), | 458 | SyntaxElement::Node(it) => it.text_range(), |
459 | SyntaxElement::Token(it) => it.range(), | 459 | SyntaxElement::Token(it) => it.text_range(), |
460 | } | 460 | } |
461 | } | 461 | } |
462 | 462 | ||
diff --git a/crates/ra_syntax/src/syntax_text.rs b/crates/ra_syntax/src/syntax_text.rs index 2ad98809b..f8ddff48e 100644 --- a/crates/ra_syntax/src/syntax_text.rs +++ b/crates/ra_syntax/src/syntax_text.rs | |||
@@ -13,7 +13,7 @@ pub struct SyntaxText { | |||
13 | 13 | ||
14 | impl SyntaxText { | 14 | impl SyntaxText { |
15 | pub(crate) fn new(node: SyntaxNode) -> SyntaxText { | 15 | pub(crate) fn new(node: SyntaxNode) -> SyntaxText { |
16 | let range = node.range(); | 16 | let range = node.text_range(); |
17 | SyntaxText { node, range } | 17 | SyntaxText { node, range } |
18 | } | 18 | } |
19 | 19 | ||
@@ -24,14 +24,14 @@ impl SyntaxText { | |||
24 | self.node.descendants_with_tokens().try_fold(init, move |acc, element| { | 24 | self.node.descendants_with_tokens().try_fold(init, move |acc, element| { |
25 | let res = match element { | 25 | let res = match element { |
26 | SyntaxElement::Token(token) => { | 26 | SyntaxElement::Token(token) => { |
27 | let range = match self.range.intersection(&token.range()) { | 27 | let range = match self.range.intersection(&token.text_range()) { |
28 | None => return Ok(acc), | 28 | None => return Ok(acc), |
29 | Some(it) => it, | 29 | Some(it) => it, |
30 | }; | 30 | }; |
31 | let slice = if range == token.range() { | 31 | let slice = if range == token.text_range() { |
32 | token.text() | 32 | token.text() |
33 | } else { | 33 | } else { |
34 | let range = range - token.range().start(); | 34 | let range = range - token.text_range().start(); |
35 | &token.text()[range] | 35 | &token.text()[range] |
36 | }; | 36 | }; |
37 | f(acc, slice)? | 37 | f(acc, slice)? |
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index 943f88de9..19bdafef2 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs | |||
@@ -33,7 +33,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) { | |||
33 | if let Some(end) = text.rfind('\'') { | 33 | if let Some(end) = text.rfind('\'') { |
34 | if let Some(without_quotes) = text.get(2..end) { | 34 | if let Some(without_quotes) = text.get(2..end) { |
35 | if let Err((off, err)) = unescape::unescape_byte(without_quotes) { | 35 | if let Err((off, err)) = unescape::unescape_byte(without_quotes) { |
36 | let off = token.range().start() + TextUnit::from_usize(off + 2); | 36 | let off = token.text_range().start() + TextUnit::from_usize(off + 2); |
37 | acc.push(SyntaxError::new(err.into(), off)) | 37 | acc.push(SyntaxError::new(err.into(), off)) |
38 | } | 38 | } |
39 | } | 39 | } |
@@ -43,7 +43,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) { | |||
43 | if let Some(end) = text.rfind('\'') { | 43 | if let Some(end) = text.rfind('\'') { |
44 | if let Some(without_quotes) = text.get(1..end) { | 44 | if let Some(without_quotes) = text.get(1..end) { |
45 | if let Err((off, err)) = unescape::unescape_char(without_quotes) { | 45 | if let Err((off, err)) = unescape::unescape_char(without_quotes) { |
46 | let off = token.range().start() + TextUnit::from_usize(off + 1); | 46 | let off = token.text_range().start() + TextUnit::from_usize(off + 1); |
47 | acc.push(SyntaxError::new(err.into(), off)) | 47 | acc.push(SyntaxError::new(err.into(), off)) |
48 | } | 48 | } |
49 | } | 49 | } |
@@ -55,7 +55,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) { | |||
55 | unescape::unescape_byte_str(without_quotes, &mut |range, char| { | 55 | unescape::unescape_byte_str(without_quotes, &mut |range, char| { |
56 | if let Err(err) = char { | 56 | if let Err(err) = char { |
57 | let off = range.start; | 57 | let off = range.start; |
58 | let off = token.range().start() + TextUnit::from_usize(off + 2); | 58 | let off = token.text_range().start() + TextUnit::from_usize(off + 2); |
59 | acc.push(SyntaxError::new(err.into(), off)) | 59 | acc.push(SyntaxError::new(err.into(), off)) |
60 | } | 60 | } |
61 | }) | 61 | }) |
@@ -68,7 +68,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) { | |||
68 | unescape::unescape_str(without_quotes, &mut |range, char| { | 68 | unescape::unescape_str(without_quotes, &mut |range, char| { |
69 | if let Err(err) = char { | 69 | if let Err(err) = char { |
70 | let off = range.start; | 70 | let off = range.start; |
71 | let off = token.range().start() + TextUnit::from_usize(off + 1); | 71 | let off = token.text_range().start() + TextUnit::from_usize(off + 1); |
72 | acc.push(SyntaxError::new(err.into(), off)) | 72 | acc.push(SyntaxError::new(err.into(), off)) |
73 | } | 73 | } |
74 | }) | 74 | }) |
diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs index f5573bd8f..c5588658d 100644 --- a/crates/ra_syntax/src/validation/block.rs +++ b/crates/ra_syntax/src/validation/block.rs | |||
@@ -16,6 +16,7 @@ pub(crate) fn validate_block_node(node: ast::Block, errors: &mut Vec<SyntaxError | |||
16 | _ => {} | 16 | _ => {} |
17 | } | 17 | } |
18 | } | 18 | } |
19 | errors | 19 | errors.extend( |
20 | .extend(node.attrs().map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().range()))) | 20 | node.attrs().map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().text_range())), |
21 | ) | ||
21 | } | 22 | } |
diff --git a/crates/ra_syntax/src/validation/field_expr.rs b/crates/ra_syntax/src/validation/field_expr.rs index 0e18bd9ca..004f199fd 100644 --- a/crates/ra_syntax/src/validation/field_expr.rs +++ b/crates/ra_syntax/src/validation/field_expr.rs | |||
@@ -7,7 +7,7 @@ use crate::{ | |||
7 | pub(crate) fn validate_field_expr_node(node: ast::FieldExpr, errors: &mut Vec<SyntaxError>) { | 7 | pub(crate) fn validate_field_expr_node(node: ast::FieldExpr, errors: &mut Vec<SyntaxError>) { |
8 | if let Some(FieldKind::Index(idx)) = node.field_access() { | 8 | if let Some(FieldKind::Index(idx)) = node.field_access() { |
9 | if idx.text().chars().any(|c| c < '0' || c > '9') { | 9 | if idx.text().chars().any(|c| c < '0' || c > '9') { |
10 | errors.push(SyntaxError::new(InvalidTupleIndexFormat, idx.range())); | 10 | errors.push(SyntaxError::new(InvalidTupleIndexFormat, idx.text_range())); |
11 | } | 11 | } |
12 | } | 12 | } |
13 | } | 13 | } |