aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_mbe/src/subtree_source.rs34
1 files changed, 4 insertions, 30 deletions
diff --git a/crates/ra_mbe/src/subtree_source.rs b/crates/ra_mbe/src/subtree_source.rs
index 997a600a5..5f20112ce 100644
--- a/crates/ra_mbe/src/subtree_source.rs
+++ b/crates/ra_mbe/src/subtree_source.rs
@@ -237,34 +237,13 @@ pub(crate) trait Querier {
237pub(crate) struct WalkerOwner<'a> { 237pub(crate) struct WalkerOwner<'a> {
238 walker: RefCell<SubTreeWalker<'a>>, 238 walker: RefCell<SubTreeWalker<'a>>,
239 offset: usize, 239 offset: usize,
240 temp: RefCell<std::collections::HashMap<usize, Option<TtToken>>>,
241} 240}
242 241
243impl<'a> WalkerOwner<'a> { 242impl<'a> WalkerOwner<'a> {
244 fn token_idx<'b>(&self, pos: usize) -> Option<TtToken> { 243 fn token_idx<'b>(&self, pos: usize) -> Option<TtToken> {
245 self.set_walker_pos(pos); 244 self.set_walker_pos(pos);
246 let walker = self.walker.borrow(); 245 let walker = self.walker.borrow();
247 let r = walker.current().cloned(); 246 walker.current().cloned()
248
249 if walker.subtree.token_trees.len() == 1 {
250 if let tt::TokenTree::Leaf(_) = &walker.subtree.token_trees[0] {
251 let mut temp = self.temp.borrow_mut();
252
253 if r.is_none() {
254 if let Some(Some(p)) = temp.get(&pos) {
255 unreachable!(
256 "nWWWWWWWWWWWW~~~~~~~~~~~~~~,\n{:#?}\n{:#?}\n{:#?}",
257 pos, p, self
258 );
259 }
260 }
261
262 // eprintln!("===>{:#?}\n{:#?}\n{:#?}", pos, r, self);
263 temp.insert(pos, r.clone());
264 }
265 }
266
267 r
268 } 247 }
269 248
270 fn start_from_nth(&mut self, pos: usize) { 249 fn start_from_nth(&mut self, pos: usize) {
@@ -275,21 +254,16 @@ impl<'a> WalkerOwner<'a> {
275 fn set_walker_pos(&self, mut pos: usize) { 254 fn set_walker_pos(&self, mut pos: usize) {
276 pos += self.offset; 255 pos += self.offset;
277 let mut walker = self.walker.borrow_mut(); 256 let mut walker = self.walker.borrow_mut();
278 while pos > walker.pos { 257 while pos > walker.pos && walker.idx != WalkIndex::Eof {
279 walker.forward(); 258 walker.forward();
280 } 259 }
281 while pos < walker.pos { 260 while pos < walker.pos {
282 walker.backward(); 261 walker.backward();
283 } 262 }
284 assert!(pos == walker.pos);
285 } 263 }
286 264
287 fn new(subtree: &'a tt::Subtree) -> Self { 265 fn new(subtree: &'a tt::Subtree) -> Self {
288 WalkerOwner { 266 WalkerOwner { walker: RefCell::new(SubTreeWalker::new(subtree)), offset: 0 }
289 walker: RefCell::new(SubTreeWalker::new(subtree)),
290 offset: 0,
291 temp: RefCell::new(Default::default()),
292 }
293 } 267 }
294 268
295 fn collect_token_tree(&mut self, n: usize) -> Vec<&tt::TokenTree> { 269 fn collect_token_tree(&mut self, n: usize) -> Vec<&tt::TokenTree> {
@@ -501,7 +475,7 @@ fn convert_ident(ident: &tt::Ident) -> TtToken {
501} 475}
502 476
503fn convert_punct(p: &tt::Punct, parent: &tt::Subtree, next: usize) -> TtToken { 477fn convert_punct(p: &tt::Punct, parent: &tt::Subtree, next: usize) -> TtToken {
504 let iter = parent.token_trees[next..].iter(); 478 let iter = parent.token_trees[next + 1..].iter();
505 let mut peek = TokenPeek::new(iter); 479 let mut peek = TokenPeek::new(iter);
506 480
507 if let Some((kind, is_joint_to_next, text, size)) = convert_multi_char_punct(p, &mut peek) { 481 if let Some((kind, is_joint_to_next, text, size)) = convert_multi_char_punct(p, &mut peek) {