aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe/src
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-04-21 21:17:49 +0100
committerEdwin Cheng <[email protected]>2019-04-21 22:04:37 +0100
commit3d1cdc834dded79aea685214562da81d60e270ce (patch)
tree91cca49d99ba49bacb81b855547d3a609f4103d8 /crates/ra_mbe/src
parent49c9686c3cb02d64c077d3002f3c68e6fa2cf407 (diff)
Fix offset bug in SourceWalker
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r--crates/ra_mbe/src/subtree_source.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/ra_mbe/src/subtree_source.rs b/crates/ra_mbe/src/subtree_source.rs
index 6d4d8fa13..20da1e9f7 100644
--- a/crates/ra_mbe/src/subtree_source.rs
+++ b/crates/ra_mbe/src/subtree_source.rs
@@ -21,6 +21,7 @@ impl<'a> From<&'a [tt::TokenTree]> for TokenSeq<'a> {
21 } 21 }
22} 22}
23 23
24#[derive(Debug)]
24enum DelimToken<'a> { 25enum DelimToken<'a> {
25 Delim(&'a tt::Delimiter, bool), 26 Delim(&'a tt::Delimiter, bool),
26 Token(&'a tt::TokenTree), 27 Token(&'a tt::TokenTree),
@@ -52,10 +53,10 @@ impl<'a> TokenSeq<'a> {
52 } 53 }
53 } 54 }
54 55
55 fn child_slice(&self) -> &[tt::TokenTree] { 56 fn child_slice(&self, pos: usize) -> &[tt::TokenTree] {
56 match self { 57 match self {
57 TokenSeq::Subtree(subtree) => &subtree.token_trees, 58 TokenSeq::Subtree(subtree) => &subtree.token_trees[pos - 1..],
58 TokenSeq::Seq(tokens) => &tokens, 59 TokenSeq::Seq(tokens) => &tokens[pos..],
59 } 60 }
60 } 61 }
61} 62}
@@ -114,7 +115,7 @@ impl<'a> SubTreeWalker<'a> {
114 WalkCursor::Token(0, convert_delim(subtree.delimiter, false)) 115 WalkCursor::Token(0, convert_delim(subtree.delimiter, false))
115 } 116 }
116 tt::TokenTree::Leaf(leaf) => { 117 tt::TokenTree::Leaf(leaf) => {
117 let next_tokens = self.ts.child_slice(); 118 let next_tokens = self.ts.child_slice(0);
118 WalkCursor::Token(0, convert_leaf(&next_tokens, leaf)) 119 WalkCursor::Token(0, convert_leaf(&next_tokens, leaf))
119 } 120 }
120 }, 121 },
@@ -190,8 +191,8 @@ impl<'a> SubTreeWalker<'a> {
190 WalkCursor::Token(new_idx, convert_delim(subtree.delimiter, backward)) 191 WalkCursor::Token(new_idx, convert_delim(subtree.delimiter, backward))
191 } 192 }
192 tt::TokenTree::Leaf(leaf) => { 193 tt::TokenTree::Leaf(leaf) => {
193 let next_tokens = top.child_slice(); 194 let next_tokens = top.child_slice(pos);
194 WalkCursor::Token(pos, convert_leaf(&next_tokens[pos..], leaf)) 195 WalkCursor::Token(pos, convert_leaf(&next_tokens, leaf))
195 } 196 }
196 }, 197 },
197 DelimToken::Delim(delim, is_end) => { 198 DelimToken::Delim(delim, is_end) => {