From 3d1cdc834dded79aea685214562da81d60e270ce Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 22 Apr 2019 04:17:49 +0800 Subject: Fix offset bug in SourceWalker --- crates/ra_mbe/src/subtree_source.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/ra_mbe') 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> { } } +#[derive(Debug)] enum DelimToken<'a> { Delim(&'a tt::Delimiter, bool), Token(&'a tt::TokenTree), @@ -52,10 +53,10 @@ impl<'a> TokenSeq<'a> { } } - fn child_slice(&self) -> &[tt::TokenTree] { + fn child_slice(&self, pos: usize) -> &[tt::TokenTree] { match self { - TokenSeq::Subtree(subtree) => &subtree.token_trees, - TokenSeq::Seq(tokens) => &tokens, + TokenSeq::Subtree(subtree) => &subtree.token_trees[pos - 1..], + TokenSeq::Seq(tokens) => &tokens[pos..], } } } @@ -114,7 +115,7 @@ impl<'a> SubTreeWalker<'a> { WalkCursor::Token(0, convert_delim(subtree.delimiter, false)) } tt::TokenTree::Leaf(leaf) => { - let next_tokens = self.ts.child_slice(); + let next_tokens = self.ts.child_slice(0); WalkCursor::Token(0, convert_leaf(&next_tokens, leaf)) } }, @@ -190,8 +191,8 @@ impl<'a> SubTreeWalker<'a> { WalkCursor::Token(new_idx, convert_delim(subtree.delimiter, backward)) } tt::TokenTree::Leaf(leaf) => { - let next_tokens = top.child_slice(); - WalkCursor::Token(pos, convert_leaf(&next_tokens[pos..], leaf)) + let next_tokens = top.child_slice(pos); + WalkCursor::Token(pos, convert_leaf(&next_tokens, leaf)) } }, DelimToken::Delim(delim, is_end) => { -- cgit v1.2.3