mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Simplify
This commit is contained in:
parent
99f1e66997
commit
6993a607cb
1 changed files with 19 additions and 24 deletions
|
@ -465,11 +465,12 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
};
|
};
|
||||||
let sa = self.analyze(&parent);
|
let sa = self.analyze(&parent);
|
||||||
let mut queue = vec![InFile::new(sa.file_id, token)];
|
let mut queue = vec![InFile::new(sa.file_id, token)];
|
||||||
|
let mut cache = self.expansion_info_cache.borrow_mut();
|
||||||
let mut res = smallvec![];
|
let mut res = smallvec![];
|
||||||
while let Some(token) = queue.pop() {
|
while let Some(token) = queue.pop() {
|
||||||
self.db.unwind_if_cancelled();
|
self.db.unwind_if_cancelled();
|
||||||
|
|
||||||
let mapped = (|| {
|
let was_not_remapped = (|| {
|
||||||
for node in token.value.ancestors() {
|
for node in token.value.ancestors() {
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
|
@ -487,7 +488,6 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let file_id = sa.expand(self.db, token.with_value(¯o_call))?;
|
let file_id = sa.expand(self.db, token.with_value(¯o_call))?;
|
||||||
let mut cache = self.expansion_info_cache.borrow_mut();
|
|
||||||
let tokens = cache
|
let tokens = cache
|
||||||
.entry(file_id)
|
.entry(file_id)
|
||||||
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
|
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
|
||||||
|
@ -503,25 +503,21 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
return (queue.len() != len).then(|| ());
|
return (queue.len() != len).then(|| ());
|
||||||
},
|
},
|
||||||
ast::Item(item) => {
|
ast::Item(item) => {
|
||||||
match self.with_ctx(|ctx| ctx.item_to_macro_call(token.with_value(item))) {
|
if let Some(call_id) = self.with_ctx(|ctx| ctx.item_to_macro_call(token.with_value(item.clone()))) {
|
||||||
Some(call_id) => {
|
let file_id = call_id.as_file();
|
||||||
let file_id = call_id.as_file();
|
let tokens = cache
|
||||||
let mut cache = self.expansion_info_cache.borrow_mut();
|
.entry(file_id)
|
||||||
let tokens = cache
|
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
|
||||||
.entry(file_id)
|
.as_ref()?
|
||||||
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
|
.map_token_down(self.db.upcast(), Some(item), token.as_ref())?;
|
||||||
.as_ref()?
|
|
||||||
.map_token_down(self.db.upcast(), None, token.as_ref())?;
|
|
||||||
|
|
||||||
let len = queue.len();
|
let len = queue.len();
|
||||||
queue.extend(tokens.inspect(|token| {
|
queue.extend(tokens.inspect(|token| {
|
||||||
if let Some(parent) = token.value.parent() {
|
if let Some(parent) = token.value.parent() {
|
||||||
self.cache(find_root(&parent), token.file_id);
|
self.cache(find_root(&parent), token.file_id);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
return (queue.len() != len).then(|| ());
|
return (queue.len() != len).then(|| ());
|
||||||
}
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -529,10 +525,9 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
})();
|
})().is_none();
|
||||||
match mapped {
|
if was_not_remapped {
|
||||||
Some(()) => (),
|
res.push(token.value)
|
||||||
None => res.push(token.value),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
|
|
Loading…
Reference in a new issue