aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src/semantics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir/src/semantics.rs')
-rw-r--r--crates/hir/src/semantics.rs66
1 files changed, 49 insertions, 17 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index c7f2c02e4..0d55e4a3e 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -362,25 +362,57 @@ impl<'db> SemanticsImpl<'db> {
362 362
363 let token = successors(Some(InFile::new(sa.file_id, token)), |token| { 363 let token = successors(Some(InFile::new(sa.file_id, token)), |token| {
364 self.db.unwind_if_cancelled(); 364 self.db.unwind_if_cancelled();
365 let macro_call = token.value.ancestors().find_map(ast::MacroCall::cast)?; 365
366 let tt = macro_call.token_tree()?; 366 for node in token.value.ancestors() {
367 if !tt.syntax().text_range().contains_range(token.value.text_range()) { 367 match_ast! {
368 return None; 368 match node {
369 } 369 ast::MacroCall(macro_call) => {
370 let file_id = sa.expand(self.db, token.with_value(&macro_call))?; 370 let tt = macro_call.token_tree()?;
371 let token = self 371 if !tt.syntax().text_range().contains_range(token.value.text_range()) {
372 .expansion_info_cache 372 return None;
373 .borrow_mut() 373 }
374 .entry(file_id) 374 let file_id = sa.expand(self.db, token.with_value(&macro_call))?;
375 .or_insert_with(|| file_id.expansion_info(self.db.upcast())) 375 let token = self
376 .as_ref()? 376 .expansion_info_cache
377 .map_token_down(token.as_ref())?; 377 .borrow_mut()
378 378 .entry(file_id)
379 if let Some(parent) = token.value.parent() { 379 .or_insert_with(|| file_id.expansion_info(self.db.upcast()))
380 self.cache(find_root(&parent), token.file_id); 380 .as_ref()?
381 .map_token_down(token.as_ref())?;
382
383 if let Some(parent) = token.value.parent() {
384 self.cache(find_root(&parent), token.file_id);
385 }
386
387 return Some(token);
388 },
389 ast::Item(item) => {
390 match self.with_ctx(|ctx| ctx.item_to_macro_call(token.with_value(item))) {
391 Some(call_id) => {
392 let file_id = call_id.as_file();
393 let token = self
394 .expansion_info_cache
395 .borrow_mut()
396 .entry(file_id)
397 .or_insert_with(|| file_id.expansion_info(self.db.upcast()))
398 .as_ref()?
399 .map_token_down(token.as_ref())?;
400
401 if let Some(parent) = token.value.parent() {
402 self.cache(find_root(&parent), token.file_id);
403 }
404
405 return Some(token);
406 }
407 None => {}
408 }
409 },
410 _ => {}
411 }
412 }
381 } 413 }
382 414
383 Some(token) 415 None
384 }) 416 })
385 .last() 417 .last()
386 .unwrap(); 418 .unwrap();