mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Use FileAstId<ast::Adt>
in nameres where appropriate instead
This commit is contained in:
parent
08adce61a1
commit
ca4baa6e55
23 changed files with 98 additions and 65 deletions
|
@ -87,6 +87,7 @@
|
|||
|
||||
use base_db::FileId;
|
||||
use hir_def::{
|
||||
attr::AttrId,
|
||||
child_by_source::ChildBySource,
|
||||
dyn_map::DynMap,
|
||||
expr::{LabelId, PatId},
|
||||
|
@ -210,19 +211,6 @@ impl SourceToDefCtx<'_, '_> {
|
|||
ast::Adt::Union(it) => self.union_to_def(InFile::new(file_id, it)).map(AdtId::UnionId),
|
||||
}
|
||||
}
|
||||
pub(super) fn attr_to_def(
|
||||
&mut self,
|
||||
InFile { file_id, value }: InFile<ast::Attr>,
|
||||
) -> Option<crate::Attr> {
|
||||
// FIXME: Use dynmap?
|
||||
let adt = value.syntax().parent().and_then(ast::Adt::cast)?;
|
||||
let attr_pos = ast::HasAttrs::attrs(&adt).position(|it| it == value)?;
|
||||
let attrs = {
|
||||
let def = self.adt_to_def(InFile::new(file_id, adt))?;
|
||||
self.db.attrs(def.into())
|
||||
};
|
||||
attrs.get(attr_pos).cloned()
|
||||
}
|
||||
pub(super) fn bind_pat_to_def(
|
||||
&mut self,
|
||||
src: InFile<ast::IdentPat>,
|
||||
|
@ -254,16 +242,16 @@ impl SourceToDefCtx<'_, '_> {
|
|||
|
||||
pub(super) fn item_to_macro_call(&mut self, src: InFile<ast::Item>) -> Option<MacroCallId> {
|
||||
let map = self.dyn_map(src.as_ref())?;
|
||||
map[keys::ATTR_MACRO].get(&src).copied()
|
||||
map[keys::ATTR_MACRO_CALL].get(&src).copied()
|
||||
}
|
||||
|
||||
pub(super) fn attr_to_derive_macro_call(
|
||||
&mut self,
|
||||
item: InFile<&ast::Adt>,
|
||||
src: InFile<ast::Attr>,
|
||||
) -> Option<&[Option<MacroCallId>]> {
|
||||
) -> Option<(AttrId, &[Option<MacroCallId>])> {
|
||||
let map = self.dyn_map(item)?;
|
||||
map[keys::DERIVE_MACRO].get(&src).map(AsRef::as_ref)
|
||||
map[keys::DERIVE_MACRO_CALL].get(&src).map(|(id, ids)| (*id, &**ids))
|
||||
}
|
||||
|
||||
fn to_def<Ast: AstNode + 'static, ID: Copy + 'static>(
|
||||
|
@ -328,7 +316,8 @@ impl SourceToDefCtx<'_, '_> {
|
|||
}
|
||||
|
||||
pub(super) fn macro_to_def(&mut self, src: InFile<ast::Macro>) -> Option<MacroDefId> {
|
||||
let makro = self.dyn_map(src.as_ref()).and_then(|it| it[keys::MACRO].get(&src).copied());
|
||||
let makro =
|
||||
self.dyn_map(src.as_ref()).and_then(|it| it[keys::MACRO_CALL].get(&src).copied());
|
||||
if let res @ Some(_) = makro {
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue