mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
cleanup
This commit is contained in:
parent
aeb5d64912
commit
44b0fe8ec7
2 changed files with 46 additions and 29 deletions
|
@ -5,6 +5,7 @@ mod source_to_def;
|
|||
use std::{cell::RefCell, fmt};
|
||||
|
||||
use base_db::{FileId, FileRange};
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
body,
|
||||
resolver::{self, HasResolver, Resolver, TypeNs},
|
||||
|
@ -909,11 +910,15 @@ impl<'db> SemanticsImpl<'db> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let attr_def =
|
||||
ast::Attr::to_def(self, self.find_file(attr.syntax()).with_value(attr.clone()))?;
|
||||
let file = self.find_file(attr.syntax());
|
||||
let adt = attr.syntax().parent().and_then(ast::Adt::cast)?;
|
||||
|
||||
let res = self.with_ctx(|ctx| {
|
||||
let attr_def = ctx.attr_to_def(file.with_value(attr.clone()))?;
|
||||
let derives = ctx
|
||||
.attr_to_derive_macro_call(file.with_value(&adt), file.with_value(attr.clone()))?;
|
||||
|
||||
let mut derive_paths = attr_def.parse_path_comma_token_tree()?;
|
||||
let derives = self.resolve_derive_macro(&attr)?;
|
||||
|
||||
let derive_idx = tt
|
||||
.syntax()
|
||||
|
@ -936,15 +941,23 @@ impl<'db> SemanticsImpl<'db> {
|
|||
while path_segment_idx < mod_path.len() {
|
||||
mod_path.pop_segment();
|
||||
}
|
||||
resolve_hir_path(
|
||||
self.db,
|
||||
&self.scope(attr.syntax()).resolver,
|
||||
&Path::from_known_path(mod_path, []),
|
||||
)
|
||||
.filter(|res| matches!(res, PathResolution::Def(ModuleDef::Module(_))))
|
||||
Some(Either::Left(mod_path))
|
||||
} else {
|
||||
// otherwise fetch the derive
|
||||
derives.get(derive_idx)?.map(PathResolution::Macro)
|
||||
Some(Either::Right(derives[derive_idx]))
|
||||
}
|
||||
})?;
|
||||
|
||||
match res {
|
||||
Either::Left(path) => resolve_hir_path(
|
||||
self.db,
|
||||
&self.scope(attr.syntax()).resolver,
|
||||
&Path::from_known_path(path, []),
|
||||
)
|
||||
.filter(|res| matches!(res, PathResolution::Def(ModuleDef::Module(_)))),
|
||||
Either::Right(derive) => derive
|
||||
.map(|call| MacroDef { id: self.db.lookup_intern_macro_call(call).def })
|
||||
.map(PathResolution::Macro),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -746,7 +746,11 @@ impl Attr {
|
|||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
return Some(paths.into_iter());
|
||||
Some(paths.into_iter())
|
||||
}
|
||||
|
||||
pub fn path(&self) -> &ModPath {
|
||||
&self.path
|
||||
}
|
||||
|
||||
pub fn string_value(&self) -> Option<&SmolStr> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue